सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
एक फ्लटर प्लगइन जो विंडोज़ में मूल win32 API का उपयोग करके सीरियल पोर्ट संचार की अनुमति देता है। इससे सीरियल पोर्ट के माध्यम से भौतिक उपकरणों, जैसे माइक्रोकंट्रोलर, सेंसर या औद्योगिक उपकरणों से सीधे कनेक्शन बनाना संभव होता है। विंडोज़ के लिए विशेष रूप से डिज़ाइन किया गया, इसमें न्यूनतम अबस्ट्रैक्शन के साथ लो-लेवल एक्सेस प्रदान करता है, जिससे डेस्कटॉप एप्लिकेशन में विश्वसनीय और कुशल सीरियल संचार की आवश्यकता वाले डेवलपर्स के लिए उपयुक्त है। पैकेज फ्लटर के इकोसिस्टम के साथ बिना किसी दिक्कत के एकीकृत होता है और हार्डवेयर-फोकस्ड प्रोजेक्ट्स के लिए आदर्श है।
उपयोग
Arduino या समान माइक्रोकंट्रोलर से कनेक्ट करना
औद्योगिक सेंसर से डेटा पढ़ना
सीरियल प्रोटोकॉल के माध्यम से हार्डवेयर डिवाइस का नियंत्रण
एम्बेडेड सिस्टम के लिए डेस्कटॉप एप्लिकेशन विकसित करना
सीरियल पेरिफेरल्स के साथ रियल-टाइम कम्युनिकेशन स्थापित करना
मुख्य विशेषताएँ
मूल win32 API एकीकरण
विंडोज़-केवल प्लेटफॉर्म समर्थन
कम लेटेंसी श्रृंखला संचार
पोर्ट खोलने/बंद करने के लिए सरल API
बॉड रेट और पैरिटी कॉन्फ़िगरेशन का समर्थन करता है
रियल-टाइम डेटा स्ट्रीमिंग
इनके लिए उपयुक्त
Windows डेस्कटॉप ऐप विकासकर्ता
हार्डवेयर इंटरफेस प्रोजेक्ट्स
आईओटी उपकरण नियंत्रण एप्लिकेशन
एम्बेडेड सिस्टम इंटीग्रेशन
रियल-टाइम डेटा एकत्रीकरण उपकरण
विचार योग्य बातें
सीमित विंडोज़ संचालन प्रणाली
कुछ संचालन के लिए प्रशासक की अधिकृत अधिकारों की आवश्यकता होती है
Linux या macOS का समर्थन नहीं है
त्रुटि के हस्तक्षेप आवश्यक है
विंडोज-विशिष्ट सिस्टम कॉल पर निर्भर
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
serial_port_win32
A SerialPort library using win32 API.
Breaking Changes from 2.x.x to 3.x.x
Due to many major changes in win32 package, this package need to break some APIs.
Some main APIs change below:
set Parity(int parity) -> set Parity(DCB_PARITY parity)
set StopBits(int stopBits) -> set StopBits(DCB_STOP_BITS stopBits)
final LPWSTR _portNameUtf16; -> final PCWSTR _portNameUtf16;
Some Exceptions change to WindowsExceptions
Deprecated
@Deprecated("Use win32 constant CLRDTR instead of this, because it is more clear to understand")
staticconstint CLRDTR = 6;
/// Clears the RTS (request-to-send) signal.@Deprecated("Use win32 constant CLRRTS instead of this, because it is more clear to understand")
staticconstint CLRRTS = 4;
/// Sends the DTR (data-terminal-ready) signal.@Deprecated("Use win32 constant SETDTR instead of this, because it is more clear to understand")
staticconstint SETDTR = 5;
/// Sends the RTS (request-to-send) signal.@Deprecated("Use win32 constant SETRTS instead of this, because it is more clear to understand")
staticconstint SETRTS = 3;
Getting Started
Get Ports
final ports = SerialPort.getAvailablePorts();
print(ports);
/// result like [COM3, COM4]
The port instance is Singleton Pattern. Don't re-create port for same Com name.
final port = SerialPort("COM5", openNow: true, ByteSize: 8, BaudRate: 9600);
// orfinal port = SerialPort("COM5", openNow: false, ByteSize: 8, BaudRate: 9600);
port.open();
// or
port.openWithSettings(BaudRate: CBR_115200);
// final port = SerialPort("COM5"); /// auto open with default settings
Read
There are several methods to read bytes from serial port.
readBytesUntil
[readBytesUntil] will read until an [expected] sequence is found
readBytes
General Read with the timeout parameter.
readFixedSizeBytes
[readFixedSizeBytes] will always read until readData.length == bytesSize.
print(await port.readBytesUntil(Uint8List.fromList("T".codeUnits))); /// '\0' is not included/// orvar read = port.readBytes(18, timeout: Duration(milliseconds: 10))..then((onValue) => print(onValue));
var result = await read;
print(result);
/// orvar fixedBytesRead = port.readFixedSizeBytes(2)..then((onValue) => print(onValue));
await fixedBytesRead;
/// see more in small example