| | |
| | | |
| | | // 启动连接 |
| | | connection.start().then(() => { |
| | | debugger; |
| | | console.log('启动连接plc'); |
| | | }); |
| | | // 断开连接 |
| | | connection.onclose(async () => { |
| | | debugger; |
| | | console.log('断开连接plc'); |
| | | }); |
| | | // 重连中 |
| | | connection.onreconnecting(() => { |
| | | debugger; |
| | | console.log('服务器已断线plc'); |
| | | }); |
| | | // 重连成功 |
| | | connection.onreconnected(() => { |
| | | debugger; |
| | | console.log('重连成功plc'); |
| | | }); |
| | | |
| | | // 关闭连接的方法 |
| | | async function stopConnection() { |
| | | try { |
| | | await connection.stop(); |
| | | console.log('连接已关闭'); |
| | | } catch (error) { |
| | | console.error('关闭连接时发生错误:', error); |
| | | } |
| | | } |
| | | // connection.on('PublicPlcConn', () => {}); |
| | | |
| | | export { connection as signalR }; |
| | | export { connection as signalR,stopConnection }; |