marcoauto Posted May 16, 2011 Share Posted May 16, 2011 ciao, I must use 3 different COMs and send to them some codes COM number1 is COM1 COM number2 is COM2 COM number3 is COM7 My program listen for a TCP packet and then send something to one of the 3 COMs (client-server solution) This is a part of the program: #include "CommMG.au3" Global $Com_Port = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "Com_Port", "Not_Found") Global $BitPerSecond = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "BitPerSecond", "Not_Found") Global $BitDati = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "BitDati", "Not_Found") Global $Parity = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "Parity", "Not_Found") Global $BitStop = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "BitStop", "Not_Found") Global $FlowControl = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "FlowControl", "Not_Found") _CommSetPort($Com_Port, $sErr , $BitPerSecond, $BitDati, $Parity, $BitStop, $FlowControl) Global $Com_Port2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "Com_Port", "Not_Found") Global $BitPerSecond2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "BitPerSecond", "Not_Found") Global $BitDati2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "BitDati", "Not_Found") Global $Parity2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "Parity", "Not_Found") Global $BitStop2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "BitStop", "Not_Found") Global $FlowControl2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "FlowControl", "Not_Found") _CommSetPort($Com_Port2, $sErr2 , $BitPerSecond2, $BitDati2, $Parity2, $BitStop2, $FlowControl2) Global $Com_Port3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "Com_Port", "Not_Found") Global $BitPerSecond3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "BitPerSecond", "Not_Found") Global $BitDati3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "BitDati", "Not_Found") Global $Parity3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "Parity", "Not_Found") Global $BitStop3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "BitStop", "Not_Found") Global $FlowControl3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "FlowControl", "Not_Found") _CommSetPort($Com_Port3, $sErr3 , $BitPerSecond3, $BitDati3, $Parity3, $BitStop3, $FlowControl3) and this is anothe part of the receve part of the program _CommSwitch(1) ;<------------ COM1 If StringInStr($Rcv,"01 00 01 00 00 00 00 01 00 07 AA 02 00 01 01 01 01 03 FF 53 0D") Then _CommSendString("SBI01O01" & @CR, 1) sleep(100) $Data1 = _CommGetString() If $Data1 = "SBUD01O1" Then $Data1 = "01 00 01 00 00 00 00 01 00 07 AA 02 00 01 01 01 01 03 FF 53 0D" EndIf If StringInStr($Rcv,"01 00 01 00 00 00 00 01 00 07 AA 02 00 02 02 07 07 03 FF 53 0D") Then _CommSendString("SBI02O07" & @CR, 1) sleep(100) $Data1 = _CommGetString() If $Data1 = "SBUD02O7" Then $Data1 = "01 00 01 00 00 00 00 01 00 07 AA 02 00 02 02 07 07 03 FF 53 0D" EndIf EndIf _CommSwitch(2) ;<------------ COM2 If StringInStr($Rcv,"Accendi Teleruttore") Then _CommSendString(83) sleep(100) EndIf If StringInStr($Rcv,"sPEGNI Teleruttore") Then _CommSendString(81) sleep(100) EndIf _CommSwitch(3) ;<------------ COM7 If StringInStr($Rcv,"Preview canale 1") Then _CommSendString(500) sleep(100) EndIf If StringInStr($Rcv,"Preview canale 2") Then _CommSendString(500) sleep(100) EndIf But this code doesn't work. There is a another way to send a packet to a particular COM port? Thanks Marco Link to comment Share on other sites More sharing options...
martin Posted May 17, 2011 Share Posted May 17, 2011 ciao, I must use 3 different COMs and send to them some codes COM number1 is COM1 COM number2 is COM2 COM number3 is COM7 My program listen for a TCP packet and then send something to one of the 3 COMs (client-server solution) This is a part of the program: #include "CommMG.au3" Global $Com_Port = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "Com_Port", "Not_Found") Global $BitPerSecond = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "BitPerSecond", "Not_Found") Global $BitDati = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "BitDati", "Not_Found") Global $Parity = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "Parity", "Not_Found") Global $BitStop = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "BitStop", "Not_Found") Global $FlowControl = IniRead(@ScriptDir & "\settings_server.ini", "Serial1", "FlowControl", "Not_Found") _CommSetPort($Com_Port, $sErr , $BitPerSecond, $BitDati, $Parity, $BitStop, $FlowControl) Global $Com_Port2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "Com_Port", "Not_Found") Global $BitPerSecond2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "BitPerSecond", "Not_Found") Global $BitDati2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "BitDati", "Not_Found") Global $Parity2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "Parity", "Not_Found") Global $BitStop2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "BitStop", "Not_Found") Global $FlowControl2 = IniRead(@ScriptDir & "\settings_server.ini", "Serial2", "FlowControl", "Not_Found") _CommSetPort($Com_Port2, $sErr2 , $BitPerSecond2, $BitDati2, $Parity2, $BitStop2, $FlowControl2) Global $Com_Port3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "Com_Port", "Not_Found") Global $BitPerSecond3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "BitPerSecond", "Not_Found") Global $BitDati3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "BitDati", "Not_Found") Global $Parity3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "Parity", "Not_Found") Global $BitStop3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "BitStop", "Not_Found") Global $FlowControl3 = IniRead(@ScriptDir & "\settings_server.ini", "Serial3", "FlowControl", "Not_Found") _CommSetPort($Com_Port3, $sErr3 , $BitPerSecond3, $BitDati3, $Parity3, $BitStop3, $FlowControl3) and this is anothe part of the receve part of the program _CommSwitch(1) ;<------------ COM1 If StringInStr($Rcv,"01 00 01 00 00 00 00 01 00 07 AA 02 00 01 01 01 01 03 FF 53 0D") Then _CommSendString("SBI01O01" & @CR, 1) sleep(100) $Data1 = _CommGetString() If $Data1 = "SBUD01O1" Then $Data1 = "01 00 01 00 00 00 00 01 00 07 AA 02 00 01 01 01 01 03 FF 53 0D" EndIf If StringInStr($Rcv,"01 00 01 00 00 00 00 01 00 07 AA 02 00 02 02 07 07 03 FF 53 0D") Then _CommSendString("SBI02O07" & @CR, 1) sleep(100) $Data1 = _CommGetString() If $Data1 = "SBUD02O7" Then $Data1 = "01 00 01 00 00 00 00 01 00 07 AA 02 00 02 02 07 07 03 FF 53 0D" EndIf EndIf _CommSwitch(2) ;<------------ COM2 If StringInStr($Rcv,"Accendi Teleruttore") Then _CommSendString(83) sleep(100) EndIf If StringInStr($Rcv,"sPEGNI Teleruttore") Then _CommSendString(81) sleep(100) EndIf _CommSwitch(3) ;<------------ COM7 If StringInStr($Rcv,"Preview canale 1") Then _CommSendString(500) sleep(100) EndIf If StringInStr($Rcv,"Preview canale 2") Then _CommSendString(500) sleep(100) EndIf But this code doesn't work. There is a another way to send a packet to a particular COM port? Thanks Marco No, it won't work because you haven't set the ports up correctly. You have misunderstood how to use the channels. By coincidence I have explained this aspect recently in the commg thread so have a look at Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
marcoauto Posted May 17, 2011 Author Share Posted May 17, 2011 Thankyou very much!!It works now :-)MarcoNo, it won't work because you haven't set the ports up correctly.You have misunderstood how to use the channels. By coincidence I have explained this aspect recently in the commg thread so have a look at Link to comment Share on other sites More sharing options...
martin Posted May 17, 2011 Share Posted May 17, 2011 Thankyou very much!!It works now :-)MarcoExcellent! Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now