本文简述如何在Smobiler中使用UsbSerial。
Step 1. 新建一个SmobilerForm窗体,再拖入UsbSerial和Button,布局如下
按钮事件代码:
//连接
private void button1_Press_2(object sender, EventArgs e)
{
usbSerial1.Connect(Smobiler.Plugins.USBSerialDataBits.DATABITS_8, Smobiler.Plugins.USBSerialStopBits.STOPBITS_1, Smobiler.Plugins.USBSerialParity.PARITY_NONE, 115200, (abj, args) =>
{
if (args.isError == true)
Toast(args.error);
});
}
//写入数据
private void button2_Press_2(object sender, EventArgs e)
{
string str = "690000001";
string print1 = "SIZE 50 mm,80 mm\r\n" + "GAP 2 mm,0 mm\r\n" + "TEXT 30,0,\"TST24.BF2 \",0,1,1,\"" + "TDW108.热转印色带" + "\n" + "TEXT 30,60,\"ROMAN.TTF \",0,1,1,\"" + "110mm×300m" + "\r\n" + "TEXT 30,120,\"TST24.BF2 \",0,1,1,\"" + "外碳" + "\r\n" + "TEXT 30,180,\"ROMAN.TTF \",0,1,1,\"" + "0101MFG18110056" + "\r\n" + "TEXT 30,240,\"ROMAN.TTF \",0,1,1,\"" + "110.DBON1.0101.4.Z1.24" + "\r\n" + "REFERENCE 0,0\r\n" + "SPEED 4.0\r\n" + "DENSITY 8\r\n" +
"SET PEEL OFF\r\n" + "SET CUTTER OFF\r\n" + "SET TEAR ON\r\n" + "DIRECTION 0\r\n" + "SHIFT 0\r\n" + "OFFSET 0 mm\r\n" + "CLS\r\n" + "QRCODE 350,0,H,4,A,0,M6,S7,\"" + str + "\"\r\n" + "TEXT 350,240,\"TSS24.BF2 \",0,1,1,\"" + "数量:100 卷 R11" + "\n" + "PRINT 1,1\r\n";
//写入信息
usbSerial1.Write(System.Text.Encoding.GetEncoding("gbk").GetBytes(print1), (abj, args) =>
{
if (args.isError == true)
Toast(args.error);
else
Toast("success");
});
}
//关闭连接
private void button3_Press_1(object sender, EventArgs e)
{
usbSerial1.Close();
}
在设计器中选中控件添加事件,数据接收在事件中
private void usbSerial1_DataReceived(object sender, USBSerialDataReceivedEventArgs e)
{
//e.Data 接收的数据
}
Step 2.测试
运行服务端后,手机上安装官网的调试工具进行测试。若是使用云平台上自行打包的客户端, 需要添加相应插件后再打包客户端。
标签:控件,args,Smobiler,mm,TEXT,void,30,串口 From: https://www.cnblogs.com/smobiler/p/17183030.html