Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

81 lines (66 sloc) 6.47 KB
串口通信Chrome插件,基于跨平台的插件通用开发框架-牛插中间件(https://github.com/wangzuohuai/WebRunLocal)开发,底层实现调用了微软串口通讯控件MSComm32.ocx。虽然主要适配谷歌浏览器,也可以用在FireFox、Opera、Edge、IE等浏览器中。通过此插件,可以在各种浏览器中通过JS非常方便的操作com口打印机、GSM 猫、手机、串口扫描枪、串口屏显、钱箱等设备。
以下是体验插件步骤:
1、访问 https://local.zorrosoft.com/ 下载最新的演示版并按TestWrl.txt说明安装;
2、请求安装插件:
{"req":"Plugin_Install","rid":1,"para":{"Name":"串口通信Chrome插件","PID":"C0B01CD6-7DD9-4D3C-B668-04168D5236FC","Date":"2019-04-21","Desc":"基于牛插中间之上用于串口通信的Chrome浏览器插件","DownAddr":"http://local.zorrosoft.com/Files/Plugin/WrlComm.pid","MD5":"ACD7C8E4FF074B546CDD528CA6DD15E5","Version":"1.0.1.2","Size":720896,"Type":1,"Cookie":"","Auth":"","TK":"9C8B3F517B6B1C81CB3C3285F5FD6195FE2AD7BF431AEAD66921A62DEFA73DDA6BD02D1450CEEBA47FE93BA5AE4324C2D3BBC39EF9B4FB4404E948B4941D265BB59148335F9B0F30842BB3425F92AC5A7E171A20BEFF99166E219151B9CE938AD07B1013E2CEC4B2E27740D06047E1E5145A257F5BE07061B5FBC04D02A627E49290B65EF5BD91757A67DEF9F2C1E6000E12BCFEE954AA13F5F02146F60494DD45B6157ED873AF056584FADD8AE45993940CB60297BFED5510925262391D47F4CCD5171A1608A4B96CB29DE76AAD7EB3C0399F002847F9363481E188648D6836D95DBDFD28C6CB3A862667D7522D011524AE871E76974DD9480A711E695FBCB6"}}
3、请求插件更新:
{"req":"Plugin_Update","rid":1,"para":{"Name":"串口通信Chrome插件","PID":"C0B01CD6-7DD9-4D3C-B668-04168D5236FC","Date":"2019-04-21","Desc":"基于牛插中间之上用于串口通信的Chrome浏览器插件","DownAddr":"http://local.zorrosoft.com/Files/Plugin/WrlComm_Update.pid","MD5":"000CA21DA02BED756E96E0FC0DB27654","Version":"1.0.1.2","Size":557056,"Type":1,"Cookie":"","Auth":"","TK":"42B336E35536C950E6C944CD0E80B4A58811F97B6F74080F0511713B20E30D2854AF095C8CEC302C9D7D68F05279B0F2DCBF455CD81E459FCF3EE0409E3189D17B999CF3348B1E50E09296691591BC770FD489610E3DA44753243BF06E576C270E5BF187A811B440A6752F4171A7690D19614DA481930BE1313A8B05B97A20E642CC7B294B2C1CE13D0CA52A41BF625716BCBFA224BA037BD40BBC272ACA1FB5427A762A3373CB07C8E5F21368280BBB147788E7AC48E40D0DB853D686BF3876F5A01ED5D0A46344B7300183252D2895E14A98A77DCDF74B700D258075BF4428E53544C2ABFA8F1AC07608B7E099DA4FE13B8E5651E915070F7964BDDB4A0AB9"}}
4、连接请求串口通讯插件服务:
2)、文件上传下载
打开测试网页,输入地址:wss://wrl.zorrosoft.com?sid=668&pid=407F58DA-67A5-4C74-B9F9-44A02A20B205&flag=1 点击连接;
支持的协议功能如下:
A、获取参数
{"req":"SP_Get","rid":1,"para":{"Items":["OutFlag","Base64","CDHolding","CDTimeout","CommID","CommPort","CTSHolding","CTSTimeout","DSRHolding","DSRTimeout","DTREnable","Handshaking","InBufferSize","InBufferCount","Break","InputLen","Interval","NullDiscard","OutBufferSize","OutBufferCount","ParityReplace","PortOpen","RThreshold","RTSEnable","Settings","SThreshold","Output","Input","CommEvent","EOFEnable","InputMode"]}}
获取指定名称的参数值,可批量获取,也可以获取单个。其中OutFlag设置SP_Event通知中未1时是否自动通知到前端,默认0,Base64指定通讯内容是否经过Base64编码后传输,默认0,如果通讯内容是二进制推荐设置为1。其它都是串口通讯的属性,Output和Input内容如果Base64设置为1表示是Base64编码后的结果,原通讯控件中布尔值规则1为真,0为假。
返回内容格式如下:
{"ret":0,"rid":1,"data":{"OutFlag":0,"Base64":0,"CDHolding":0,"CDTimeout":0,"CommID":-1,"CommPort":1,"CTSHolding":0,"CTSTimeout":0,"DSRHolding":0,"DSRTimeout":0,"DTREnable":0,"Handshaking":0,"InBufferSize":1024,"InBufferCount":0,"Break":0,"InputLen":0,"Interval":1000,"NullDiscard":0,"OutBufferSize":512,"OutBufferCount":0,"OutBufferCount":"?","PortOpen":0,"RThreshold":0,"RTSEnable":0,"Settings":"9600,n,8,1","SThreshold":0,"Output":"","Input":"","CommEvent":-4083,"EOFEnable":0,"InputMode":0}}
请求Items中的每个名称都对应自己名称的值
B、设置参数
{"req":"SP_Put","rid":2,"para":{"OutFlag":0,"Base64":0,"CDHolding":0,"CDTimeout":0,"CommID":-1,"CommPort":1,"CTSHolding":0,"CTSTimeout":0,"DSRHolding":0,"DSRTimeout":0,"DTREnable":0,"Handshaking":0,"InBufferSize":1024,"InBufferCount":0,"Break":0,"InputLen":0,"Interval":1000,"NullDiscard":0,"OutBufferSize":512,"OutBufferCount":0,"OutBufferCount":"?","PortOpen":0,"RThreshold":0,"RTSEnable":0,"Settings":"9600,n,8,1","SThreshold":0,"Output":"","Input":"","CommEvent":-4083,"EOFEnable":0,"InputMode":0}}
设置指定名称的参数值,规则和获取参数类似,Output和Input设置内容如果Base64设置为1,则必须是经过Base64编码后的内容。
返回内容格式如下:
{"ret":0,"rid":2,"data":{"OutFlag":1,"Base64":1,"CDHolding":0,"CDTimeout":1,"CommID":0,"CommPort":1,"CTSHolding":0,"CTSTimeout":1,"DSRHolding":0,"DSRTimeout":1,"DTREnable":1,"Handshaking":1,"InBufferSize":1,"InBufferCount":1,"Break":1,"InputLen":1,"Interval":1,"OutBufferSize":1,"OutBufferCount":1,"PortOpen":0,"RThreshold":1,"RTSEnable":1,"Settings":1,"SThreshold":1,"CommEvent":0,"EOFEnable":1,"InputMode":1}}
每个设置结果,在对应的结果中,1成功,0失败
5、事件通知
5.1 收到内容通知
{"event":"SP_Input","data":{"Content":""}} 如果Base64为1,内容Content里是Base64编码后的结果,实际使用时请用Base64编码还原内容
5.2 发送内容通知
{"event":"SP_Output","data":{"Content":""}} 如果Base64为1,内容Content里是Base64编码后的结果,实际使用时请用Base64编码还原内容
5.3 通讯事件通知
{"event":"SP_Event","data":{"ID":""}} "ID为事件类型 1发送事件、3 clear-to-send 线变化、4 data-set ready 线变化、5 carrier detect 线变化、6 振铃检测、7 文件结束
5.3 错误事件通知
{"event":"SSP_Error","data":{"ID":""}} "ID为错误类型:
comInvalidPropertyValue = 380,无效属性值
comSetNotSupported = 383,属性为只读
comGetNotSupported = 394,属性为只写
comPortOpen = 8000,端口打开时操作不合法
8001 超时值必须大于 0
comPortInvalid = 8002,无效端口号
8003 属性只在运行时有效
8004 属性在运行时为只读
comPortAlreadyOpen = 8005,端口已经打开
8006 设备标识符无效或不支持该标识符
8007 不支持设备的波特率
8008 指定的字节大小无效
8009 缺省参数错误
8010 硬件不可用(被其它设备锁定)
8011 函数不能分配队列
comNoOpen = 8012,设备没有打开
8013 设备已经打开
8014 不能使用通信通知
comSetCommStateFailed = 8015,不能设置端口状态
8016 不能设置 comm 事件屏蔽
comPortNotOpen = 8018,仅当端口打开时操作才有效
8019 设备忙
comReadError = 8020,读端口设备错误
comDCBError = 8021,为该端口检索设备控制块时的内部错误
comBreak = 1001,接收到中断信号
comCTSTO = 1002, Clear-to-send 超时
comDSRTO = 1003,Data-set ready 超时
comFrame = 1004,帧错误
comOverrun = 1006,端口超速
comCDTO = 1007,Carrier detect 超时
comRxOver = 1008,接收缓冲区溢出
comRxParity = 1009,Parity 错误
comTxFull = 1010,传输缓冲区满
comDCB = 1011检索端口 设备控制块 (DCB) 时的意外错误
You can’t perform that action at this time.