用aardio 调用C#串口,希望大老封装成库,本人还在学习中。。。
//串口
//https://learn.microsoft.com/zh-cn/dotnet/api/system.io.ports.serialport.datareceived?view=netframework-4.8
import dotNet
import System
System.IO.Ports.SerialErrorReceivedEventHandler=function(...){
console.dump(...)
}
mySerialPort={}
mySerialPort = System.IO.Ports.SerialPort("COM3");
mySerialPort.BaudRate = 115200;
mySerialPort.Parity = System.IO.Ports.Parity.None;
mySerialPort.StopBits = System.IO.Ports.StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = System.IO.Ports.Handshake.None;
mySerialPort.RtsEnable = false;
mySerialPort.ReadTimeout = 800;
mySerialPort.WriteTimeout = 500;
mySerialPort.DataReceived=function(sender, e){
Received=sender.ReadExisting();
if(#Received > 0){
console.log("Data Received:")
console.debug(string.trim(string.hex(Received," ")))
//console.dump(Received)
}
}
try{
mySerialPort.Open()
}
catch(e){
console.log(e)
}
mySerialPort.Write("Write(String)");
A={Byte k[]={0X41,0X54,0X4F,0X4D,0X21,0X04,0X00,0X00,0X00,0X00,0XCD,0X6C}}
for(i=1;50000;1){
console.log(i)
mySerialPort.Write(A.k, 0, #A.k)
win.delay(2)
}