Sign in to follow this  
Followers 0
seesoe

serial port to tcp

4 posts in this topic

i need a program that will send serial port data over the LAN to another computer as a virtual serial port as if it was plugged into that computer.

there is programs out there yes but they are not free and i can't find any free ones + i have a program in autoit that i can just integrate the script into it and have on system do everything.

for the sake of know how to do this and get it working i would like to just have a simple detect and pick com port on the server pc with tcp port input to use, and on the client pc just a simple type ip of the server and what com port to set it as on that pc with a simple box to display incoming raw data. i can then manipulate that setup and intergrate it into my gps program "Autoogle Tracker".

im not sure how to start this project so if someone can help me please it would be VERY much aprricated.

thanks in advanced:)

cheer

Share this post


Link to post
Share on other sites



i managed to get a VERY early beta, but i guess its a start, can someone help me in the right direction please?

you must run server then the client, they are made to work on the same pc, if you want to use it as a real client server just edit the ip's and also you will see a variable in there that you can set to send static test text or the real com to test if com scripts are working.

server

#include <GUIConstants.au3>
#include <staticconstants.au3>
#include <CommMG.au3>

$iniName = "Settings.ini"

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Serial Port TCP - Server", 266, 214, 217, 121)
$ComList = GUICtrlCreateList("", 16, 24, 73, 175)
$Group1 = GUICtrlCreateGroup("Select COM Port", 8, 8, 89, 193)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("TCP Port", 112, 8, 61, 41)
$TCPport = GUICtrlCreateInput("1004", 127, 24, 33, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Connected IP", 112, 64, 137, 41)
$ClientIP = GUICtrlCreateLabel("No Client Detected", 120, 81, 118, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Status = GUICtrlCreateLabel("Server Disabled", 112, 161, 135, 35)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0xB20000)
$DCclient = GUICtrlCreateButton("Disconnect Client", 112, 120, 135, 25)
$power = GUICtrlCreateButton("Start", 192, 24, 51, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

If FileExists( @ScriptDir & '/' & $iniName) Then
    GUICtrlSetData ($TCPport, IniRead ($iniName, "TCP", "Port", ""))
EndIf

$portlist = _CommListPorts(0);find the available COM ports and write them into the ports combo
If @error = 1 Then 
    MsgBox(0,'trouble getting portlist','Program will terminate!')
    Exit
EndIf
For $pl = 1 To $portlist[0]
    GUICtrlSetData($ComList,$portlist[$pl]);_CommListPorts())
Next
GUICtrlSetData(-1, $ComList,$portlist[1]);show the first port found

TcpStartUp ()
Global $Connected_Socket = ('-1')
Global $IP = @IpAddress1 ; This Is The Local IP.. 
Global $Port = ('1004')
Global $Server = TcpListen ($IP, $Port, '1')
If $Server = ('-1') Then Exit MsgBox ('16','Error Code 01','Cannot Start Server On IP : ' & $IP & ', Port : ' & $Port, '0')

_Accept_Connection ()

$connected = False

While 1
    Sleep ('150')
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then 
        IniWrite ($iniName, "TCP", "Port", GUICtrlRead($TCPport))
            TcpCloseSocket ($Connected_Socket)
        _System_Connections_Off ()
    EndIf
    
    If $msg = $power Then
        If Not $connected Then
            Local $sportSetError
            $setport = StringReplace(GUICtrlRead($ComList),'COM','')
            If _CommSetPort($setport,$sportSetError, 4800, 8, 0, 1, 0) Then
                $connected = True
                GuiCtrlSetdata($power, "Stop")
                GUICtrlSetBkColor($Status, 0x6BB200)
                GUICtrlSetData($Status, "  Broadcasting")
                TcpStartUp ()
                $comData = _CommGetstring()
                $set_test_string = "123"
                ;USE SET_TEST_STRING TO TEST SCRIPT WITHOUT COM AND SEND 123
                TcpSend ($Connected_Socket, $comData)
            Else
                GUICtrlSetBkColor($Status, 0x6BB200)
                $connected = False
                GuiCtrlSetdata($power, "Reset")
                GUICtrlSetData($Status, "Pick Serial Port!")
                TcpSend ($Connected_Socket, 'No Serial Data')
            EndIf
        Else
            GUICtrlSetBkColor($Status, 0xB20000)
            $connected = False
            GuiCtrlSetdata($power, "Start")
            GUICtrlSetData($Status, "Server Disabled")
            _Commcloseport()
            TcpSend ($Connected_Socket, '/Command.Exit')
            TcpCloseSocket ($Connected_Socket)
        EndIf
    EndIf

    if $msg = $DCclient Then
        TcpSend ($Connected_Socket, '/Command.Exit')
        TcpCloseSocket ($Connected_Socket)
        GUICtrlSetBkColor($Status, 0xB20000)
        GUICtrlSetData($Status, "Client Disconnected")
    EndIf

WEnd

_System_Connections_Off ()

Func _Accept_Connection ()
    Do
    Sleep ('10')
    $Connected_Socket = TcpAccept ($Server)
    Until $Connected_Socket <> ('-1')
EndFunc

Func _System_Connections_Off ()
    TcpCloseSocket ($Connected_Socket)
    _Commcloseport()
    Exit
EndFuncoÝ÷ ÙÉbz{ZºÚ"µÍÚ[ÛYH   ÑÕRPÛÛÝ[Ë]LÉÝÂÚ[ÛYH  ÜÝ]XØÛÛÝ[Ë]LÉÝÂÈÚ[ÛYH  ÐÛÛ[SQË]LÉÝÂÔYÚ[ÛÈÈÈÕTÛÙHÕRHÙXÝ[ÛÈÈÈÜOBÌÍÑÜLÈHÕRPÜX]J    ][ÝÔÙX[ÜÔHÛY[ ][ÝËËM
LLJBÌÍÙÜ^HHÕRPÝÜX]QY]
    ][ÝÉ][ÝËMÌËLÍÊBÌÍÔÝ]ÈHÕRPÝÜX]SX[
    ][ÝÈÜÝÝÛÛXÝY    ][ÝËMMKÌKÍJBÕRPÝÙ]Û
LKL ][ÝÓTÈØ[ÈÙY][ÝÊBÕRPÝÙ]ÛÛÜLKBÕRPÝÙ]ÐÛÛÜLK
BÕRTÙ]Ý]JÕ×ÔÒÕÊBÑ[YÚ[ÛÈÈÈSÛÙHÕRHÙXÝ[ÛÈÈÂÜÝ

BÛØ[  ÌÍÐÛÛXÝYÔÛØÚÙ]H
    ÌÎNËLIÌÎNÊBÛØ[  ÌÍÒTHYÜÌHÈÈÈHØØ[TÛØ[    ÌÍÔÜH
    ÌÎNÌL
    ÌÎNÊBÛØ[   ÌÍÐÛÛXÝHÜÛÛXÝ
    ÌÍÒT ÌÍÔÜ
BÒY    ÌÍÐÛÛXÝH
    ÌÎNËLIÌÎNÊH[^]ÙÐÞ
    ÌÎNÌMÌÎNË ÌÎNÑÜÛÙHIÌÎNË  ÌÎNÐØ[ÝÛÛXÝÈÙÛT  ÌÎNÈ [È ÌÍÒT [È ÌÎNËÜ   ÌÎNÈ [È ÌÍÔÜ    ÌÎNÌ ÌÎNÊBÌÍØÛÛXÝYH[ÙHÚ[HBTÛY
    ÌÎNÌML   ÌÎNÊBIÌÍÛÙÈHÕRQÙ]ÙÊ
BBRY    ÌÍÛÙÈH ÌÍÑÕRWÑUSÐÓÔÑH[BWÔÞÝ[WÐÛÛXÝ[Û×ÓÙ

BQ[YBBBBIÌÍÑ]HHÜXÝ
    ÌÍÐÛÛXÝ   ÌÎNÌL    ÌÎNÊBBRY ÌÍÑ]H    ÉÝÈ  ÌÎNÉÌÎNÈ[BRYÝ    ÌÍØÛÛXÝY[BBYÝZXÝÙ]]J   ÌÍÙÜ^K  ÌÍÑ]JBBBIÌÍØÛÛXÝYHYBBBYÝZXÝÙ]]J ÌÍÔÝ]Ë ][ÝÒÜÝÛÛXÝY  ][ÝÊBBBQÕRPÝÙ]ÐÛÛÜ ÌÍÔÝ]Ë

BBQ[ÙBBBQÕRPÝÙ]ÐÛÛÜ ÌÍÔÝ]Ë
BBBIÌÍØÛÛXÝYH[ÙBBBQÕRPÝÙ]]J   ÌÍÔÝ]Ë ][ÝÒÜÝØÛÛXÝY    ][ÝÊBBQ[YQ[YBZYÝ[Ò[Ý
    ÌÍÑ]K    ÌÎNÓÈÙX[]IÌÎNÊHH    ÌÎNÌIÌÎNÈ[BYÝZXÝÙ]]J   ÌÍÜÝ]Ë ][ÝÓÈÙX[]H]XÝY ][ÝÊBQ[YBRYÝ[Ò[Ý
    ÌÍÑ]K    ÌÎNËÐÛÛ[X[^]  ÌÎNÊHH   ÌÎNÌIÌÎNÈ[BUÜÛÜÙTÛØÚÙ]
    ÌÍÐÛÛXÝ
BQ[YÑ[[ÈÔÞÝ[WÐÛÛXÝ[Û×ÓÙ

BUÜÛÜÙTÛØÚÙ]
    ÌÍÐÛÛXÝYÔÛØÚÙ]
BN×ÐÛÛ[XÛÜÙÜ

BQ^][[

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

bump

I haven't tried your script but what is the problem you have with what you have written so far?

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0