Comments (6)
Is this is what you guys are trying to achieve?
The counter is from the Arduino.
2022-12-22.19-39-18.mp4
Super simple Arduino code:
int i = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(i);
i++;
delay(1000);
}
Flutter (Dart) code:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_libserialport/flutter_libserialport.dart';
class ScorePage extends StatefulWidget {
const ScorePage({super.key});
@override
State<ScorePage> createState() => _ScorePageState();
}
class _ScorePageState extends State<ScorePage> {
SerialPort port = SerialPort('COM9');
late SerialPortReader reader;
@override
void initState() {
super.initState();
var res = port.openRead();
if (!res) {
print('Error opening port:${port.name}');
// handle to close reconnet
}
var portConfig = SerialPortConfig()
..baudRate = 9600
..bits = 8
..stopBits = 1;
port.config = portConfig;
reader = SerialPortReader(port);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: StreamBuilder<Uint8List>(
stream: reader.stream,
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return const Text('Awaiting result...');
}
var decodedString = String.fromCharCodes(snapshot.data!);
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Counter from Arduino:',
),
Text(
decodedString,
style: Theme.of(context).textTheme.headline1,
),
],
);
},
),
),
);
}
@override
void dispose() {
port.close();
super.dispose();
}
}
Sometimes you may need to disconnect and reconnect the USB cable.
from flutter_libserialport.
I am interested in the answer too. I am trying to use this for a Flutter desktop app with ESP32
from flutter_libserialport.
Have you solved this yet? I want use this for a Flutter desktop app with STM32.
from flutter_libserialport.
Having same issue.
But open the serial port in Arduino IDE first then open the port with this package everything works fine.
Did anyone solve this problem?
from flutter_libserialport.
Is this is what you guys are trying to achieve?
The counter is from the Arduino.
2022-12-22.19-39-18.mp4
Super simple Arduino code:int i = 0; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: Serial.println(i); i++; delay(1000); }Flutter (Dart) code:
import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_libserialport/flutter_libserialport.dart'; class ScorePage extends StatefulWidget { const ScorePage({super.key}); @override State<ScorePage> createState() => _ScorePageState(); } class _ScorePageState extends State<ScorePage> { SerialPort port = SerialPort('COM9'); late SerialPortReader reader; @override void initState() { super.initState(); var res = port.openRead(); if (!res) { print('Error opening port:${port.name}'); // handle to close reconnet } var portConfig = SerialPortConfig() ..baudRate = 9600 ..bits = 8 ..stopBits = 1; port.config = portConfig; reader = SerialPortReader(port); } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: StreamBuilder<Uint8List>( stream: reader.stream, builder: (context, snapshot) { if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } if (snapshot.connectionState == ConnectionState.waiting) { return const Text('Awaiting result...'); } var decodedString = String.fromCharCodes(snapshot.data!); return Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Text( 'Counter from Arduino:', ), Text( decodedString, style: Theme.of(context).textTheme.headline1, ), ], ); }, ), ), ); } @override void dispose() { port.close(); super.dispose(); } }Sometimes you may need to disconnect and reconnect the USB cable.
This closes the inquiry, thanks @iqfareez
from flutter_libserialport.
Is this is what you guys are trying to achieve?
The counter is from the Arduino.
2022-12-22.19-39-18.mp4
Super simple Arduino code:int i = 0; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: Serial.println(i); i++; delay(1000); }Flutter (Dart) code:
import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_libserialport/flutter_libserialport.dart'; class ScorePage extends StatefulWidget { const ScorePage({super.key}); @override State<ScorePage> createState() => _ScorePageState(); } class _ScorePageState extends State<ScorePage> { SerialPort port = SerialPort('COM9'); late SerialPortReader reader; @override void initState() { super.initState(); var res = port.openRead(); if (!res) { print('Error opening port:${port.name}'); // handle to close reconnet } var portConfig = SerialPortConfig() ..baudRate = 9600 ..bits = 8 ..stopBits = 1; port.config = portConfig; reader = SerialPortReader(port); } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: StreamBuilder<Uint8List>( stream: reader.stream, builder: (context, snapshot) { if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } if (snapshot.connectionState == ConnectionState.waiting) { return const Text('Awaiting result...'); } var decodedString = String.fromCharCodes(snapshot.data!); return Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Text( 'Counter from Arduino:', ), Text( decodedString, style: Theme.of(context).textTheme.headline1, ), ], ); }, ), ), ); } @override void dispose() { port.close(); super.dispose(); } }Sometimes you may need to disconnect and reconnect the USB cable.
No, i need to perform write and read. read is working but write isn't working
from flutter_libserialport.
Related Issues (20)
- Support for Gradle 8.3.0: Define namespace HOT 2
- Problème lecture et écriture
- android support HOT 5
- Windwos Incomplete writing HOT 1
- read not working on Windows HOT 4
- Cant open port on MacOS HOT 2
- Cant open port on Windows
- Failed to load dynamic library 'libserialport.so' HOT 3
- Android: Namespace not specified
- SerialPortError: Input/output error, errno = 5
- Multiple instances of serial port reader in call stack
- Android support
- Can only read one time HOT 1
- Can't change baud rate on MacOS HOT 1
- error: resource android:attr/lStar not found. HOT 1
- How to read serial data HOT 2
- No running
- Can't read buffer that was not empty before opening serial port (Windows) HOT 3
- How to configure baudrate and port HOT 2
- Can't run android app HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_libserialport.