RS232 serial terminal - WIN10 x64

Just starting out? Need help? Post your questions and find answers here.
marc_256
Enthusiast
Enthusiast
Posts: 743
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

RS232 serial terminal - WIN10 x64

Post by marc_256 »

Hi,

I need a RS232 serial terminal - WIN10 x64
but I did not find some working examples on the forum.

Is there someone who haves a small send/receive terminal,
with a send frame and receive frame ?

thanks,
Marc,

I do not have time to write one myself so, very welcome ...
I tested realterm but is not working on WIN10 x64
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: RS232 serial terminal - WIN10 x64

Post by infratec »

Hi,

there are many examples here. Search for 'serialport'.

But it always depends on your needs.
How does your 'frame' look?
Without this information it is very difficult to help.
Do you want 2 gadgets: one for transmit, one for receive?
Or a real terminal like PuTTY?
Or ...
marc_256
Enthusiast
Enthusiast
Posts: 743
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: RS232 serial terminal - WIN10 x64

Post by marc_256 »

hi infratec,

I was looking in the search with 'RS232 terminal',
with 'serialport' I found this one

viewtopic.php?f=12&t=30372&hilit=serialport

I think I can start with this one ...
I need a 'send' string gadget, and a 'receive' text gadget.
My little robot need to receive 3x "CR" to auto adapt baud rate,
then I send some text, ready.

Then I need to upload a program file in my robot memory,
and wait till I receive a ready back.

Yes, PuTTY is the max ... :mrgreen:

thanks,
marc,

http://www.marc-systems.be/ms_2018/webs ... l/home.htm
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: RS232 serial terminal - WIN10 x64

Post by infratec »

A first start:

Code: Select all

EnableExplicit

#COMMaxPorts = 30

Enumeration #PB_Event_FirstCustomValue
  #ComThread_Started
  #ComThread_ByteReceived
  #ComThread_LineReceived
  #ComThread_Finished
EndEnumeration

Enumeration
  #ComText
  #ComCombo
  #ConnectButton
  #SendText
  #SendString
  #SendButton
  #ReceiveText
  #ReceiveEdit
EndEnumeration

Structure ThreadParameterStructure
  Thread.i
  Semaphore.i
  Com$
  Com.i
  Receive$
  Exit.i
EndStructure


Global NewList COMUsablePorts.s()


Procedure COMGetAvailablePorts()

  Protected NewList COMPortNameList.s()
  Protected i.i, Directory.i, Com.i
  
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    For i = 1 To #COMMaxPorts
      AddElement(COMPortNameList())
      COMPortNameList() = "COM" + Str(i)
    Next i
  CompilerEndIf
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    Directory = ExamineDirectory(#PB_Any, "/dev", "ttyUSB*")
    If Directory
      While NextDirectoryEntry(Directory)
        AddElement(COMPortNameList())
        COMPortNameList() = "/dev/" + DirectoryEntryName(Directory)
      Wend
      FinishDirectory(Directory)
    EndIf
  CompilerEndIf
  
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    Directory = ExamineDirectory(#PB_Any, "/dev", "tty.usbserial*")
    If Directory
      While NextDirectoryEntry(Directory)
        AddElement(COMPortNameList())
        COMPortNameList() = "/dev/" + DirectoryEntryName(Directory)
      Wend
      FinishDirectory(Directory)
    EndIf
  CompilerEndIf
  
  ForEach COMPortNameList()
    Com = OpenSerialPort(#PB_Any, COMPortNameList(), 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1, 1)
    If Com
      AddElement(COMUsablePorts())
      COMUsablePorts() = COMPortNameList()
      CloseSerialPort(Com)
    EndIf
  Next
  
  FreeList(COMPortNameList())
  
EndProcedure




Procedure ComThread(*Parameter.ThreadParameterStructure)
  
  Protected Byte.a, ReceivedBytes.i
  
  
  PostEvent(#ComThread_Started)
  
  *Parameter\Com = OpenSerialPort(#PB_Any, *Parameter\Com$, 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
  If *Parameter\Com
    
    WriteSerialPortString(*Parameter\Com, #CR$ + #CR$ + #CR$)
    
    Repeat
      If AvailableSerialPortInput(*Parameter\Com)
        If ReadSerialPortData(*Parameter\Com, @Byte, 1) = 1
          ReceivedBytes + 1
          PostEvent(#ComThread_ByteReceived, 0, 0, 0, ReceivedBytes)
          If Byte = #CR
            PostEvent(#ComThread_LineReceived)
            WaitSemaphore(*Parameter\Semaphore)
          Else
            *Parameter\Receive$ + Chr(Byte)
          EndIf
        EndIf
      Else
        Delay(10)
      EndIf
    Until *Parameter\Exit
    
    CloseSerialPort(*Parameter\Com)
    
  EndIf
  
  PostEvent(#ComThread_Finished)
  
EndProcedure


Define.i Event, Exit
Define ThreadParameter.ThreadParameterStructure

COMGetAvailablePorts()

OpenWindow(0, 0, 0, 400, 300, "Serialport", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

TextGadget(#ComText, 10, 10, 50, 20, "Port")
ComboBoxGadget(#ComCombo, 70, 10, 100, 20)
ForEach COMUsablePorts()
  AddGadgetItem(#COMCombo, -1, COMUsablePorts())
Next
SetGadgetState(#ComCombo, 0)
ButtonGadget(#ConnectButton, 180, 10, 80, 20, "Connect")

TextGadget(#SendText, 10, 40, 50, 20, "Send")
StringGadget(#SendString, 70, 40, 200, 20, "")
ButtonGadget(#SendButton, 280, 40, 80, 20, "Send")
DisableGadget(#SendString, #True)
DisableGadget(#SendButton, #True)

TextGadget(#ReceiveText, 10, 70, 50, 20, "Receive")
EditorGadget(#ReceiveEdit, 70, 70, 200, 100, #PB_Editor_ReadOnly)
DisableGadget(#ReceiveEdit, #True)

CreateStatusBar(0, WindowID(0))
AddStatusBarField(100)
AddStatusBarField(100)

StatusBarText(0, 0, "Disconnected", #PB_StatusBar_Center)

ThreadParameter\Semaphore = CreateSemaphore()

Repeat
  
  Event = WaitWindowEvent()
  
  Select Event
    Case #ComThread_Started
      SetGadgetText(#ConnectButton, "Disconnect")
      DisableGadget(#ComCombo, #True)
      StatusBarText(0, 0, "Connected", #PB_StatusBar_Center)
      DisableGadget(#SendString, #False)
      DisableGadget(#SendButton, #False)
      DisableGadget(#ReceiveEdit, #False)
      
    Case #ComThread_ByteReceived
      StatusBarText(0, 1, Str(EventData()), #PB_StatusBar_Center)
      
    Case #ComThread_LineReceived
      AddGadgetItem(#ReceiveText, -1, ThreadParameter\Receive$)
      ThreadParameter\Receive$ = ""
      SignalSemaphore(ThreadParameter\Semaphore)
      
    Case #ComThread_Finished
      SetGadgetText(#ConnectButton, "Connect")
      DisableGadget(#ComCombo, #False)
      StatusBarText(0, 0, "Disconnected", #PB_StatusBar_Center)
      DisableGadget(#SendString, #True)
      DisableGadget(#SendButton, #True)
      DisableGadget(#ReceiveEdit, #True)
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #ConnectButton
          If GetGadgetText(#ConnectButton) = "Connect"
            StatusBarText(0, 1, "")
            ThreadParameter\Com$ = GetGadgetText(#ComCombo)
            ThreadParameter\Exit = #False
            ThreadParameter\Thread = CreateThread(@ComThread(), @ThreadParameter)
          Else
            ThreadParameter\Exit = #True
          EndIf
          
        Case #SendButton
          WriteSerialPortString(ThreadParameter\Com, GetGadgetText(#SendString))
          
      EndSelect
      
    Case #PB_Event_CloseWindow
      Exit = #True
      
  EndSelect
  
Until Exit

If IsThread(ThreadParameter\Thread)
  ThreadParameter\Exit = #True
  If WaitThread(ThreadParameter\Thread, 3000) = 0
    KillThread(ThreadParameter\Thread)
  EndIf
EndIf

FreeSemaphore(ThreadParameter\Semaphore)
Bernd
marc_256
Enthusiast
Enthusiast
Posts: 743
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: RS232 serial terminal - WIN10 x64

Post by marc_256 »

Hi Bernd,

thanks for the nice start ...
gone adapt it fore my needs.

My small robot will thank you via this communication :mrgreen:

marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
zefiro_flashparty
User
User
Posts: 74
Joined: Fri Mar 04, 2005 7:46 pm
Location: argentina

Re: RS232 serial terminal - WIN10 x64

Post by zefiro_flashparty »

I was experimenting a little, to communicate with my arduino using the coms and the usb, I do not know if it is the same but I managed to read the com, and also send things, I'm not sure what you need to do but maybe the example will serve you, I could not do it walk correctly, even,
for example I read what the accelerometer sends me, and I send commands to move motors, but when I send and receive at the same time, it gets a bit complicated.
Something important is the speed of the connection, you have to know well at what speed works the device to which you connect.
in the arduino one sets the speed, ejm 9600 115200 etc.
if it is not the same speed of the two sides, one reads characters without sense, as if it were Chinese.
and in the same way what you send will not be understood.

Code: Select all

ShowDebugOutput()

Port$ = "COM5"

;Com_ID = OpenSerialPort(0, Port$, 115200, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)

Com_ID = OpenSerialPort(0, Port$, 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
Delay(2000);_WAIT TO CONNECT


While AvailableSerialPortInput(Com_ID) > 0
  ;-RECIVE
  Delay(100)
   If ReadSerialPortData(Com_ID, @Buffer, 1)
       Line$ + Chr(Buffer)
   EndIf
   ;send A NUMBER
   a$=Str(a);---- NUMBER OR WORDS.
key.s= a$+ #CRLF$;<LF> ;<-- NEED ADD LINE FEED, TO FINISH
Debug key.s      
    *buffer2 = AllocateMemory(1024);--MAKE BUFFER
PokeS(*Buffer2, key.s+a$);--POKE BUFFER
  r2=WriteSerialPortString(Com_ID, key.s, #PB_Ascii);--SEND
  ;       Debug "SEND"
    
   
 Wend

Debug Line$

CloseSerialPort(Com_ID)
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)
zefiro_flashparty
User
User
Posts: 74
Joined: Fri Mar 04, 2005 7:46 pm
Location: argentina

Re: RS232 serial terminal - WIN10 x64

Post by zefiro_flashparty »

It cost me a lot to be able to make that work
the parity options, the handshake,
according to the device you use, you have to look for information about the protocol you use, I do not remember where you learned that,
but I think I had to use a sniffer of the com, to see how and what the arduino was sending

OpenSerialPort(0, Port$, 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)
zefiro_flashparty
User
User
Posts: 74
Joined: Fri Mar 04, 2005 7:46 pm
Location: argentina

Re: RS232 serial terminal - WIN10 x64

Post by zefiro_flashparty »

How did you make your robot? Do you use an old PC with the com?
or are you using arduino? :o :P

I was using it with a arduino mega,
with the shield of 4 dc motors.
and with the accelerometer,

the shell examples of the arduino I did not get any
but I discovered how to communicate simpler without libraries
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: RS232 serial terminal - WIN10 x64

Post by infratec »

Hi zefiro,

nice that you try to help.

If I look at your code, I see many points which are ... improvable.
If you need the Delays() in your code, then your code does not fit your problem/protocol.

Maybe you need a state machine, or if only strings are send with CR as termination, then you need
to detect the CRs.

Send and receive should also never be a problem.

I modified your example a bit. Maybe it helps you to find a better/safer implementation.

Code: Select all

EnableExplicit

#Port$ = "COM5"

Define Com_ID.i, Byte.a, Line$

;Com_ID = OpenSerialPort(#PB_Any, #Port$, 115200, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
Com_ID = OpenSerialPort(#PB_Any, #Port$, 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
If Com_ID
  
  Repeat
    If AvailableSerialPortInput(Com_ID) > 0
      If ReadSerialPortData(Com_ID, @Byte, 1) = 1
        If Byte = #CR
          Break
        Else
          Line$ + Chr(Byte)
        EndIf
      EndIf
    Else
      Delay(10)
    EndIf
  ForEver
  
  Debug Line$
  
  WriteSerialPortString(Com_ID, "123" + #CR$, #PB_Ascii)
  
  CloseSerialPort(Com_ID)
EndIf
Bernd
marc_256
Enthusiast
Enthusiast
Posts: 743
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: RS232 serial terminal - WIN10 x64

Post by marc_256 »

Hi infratec and zefiro_flashparty,

thanks for the help here,
I just finished my UI

Image

Now I need to do the programming ...
I need also to click on a file and to upload it to my robot.

@ zefiro_flashparty,
My robot is based on an old 68000 cpu SBC, with duart who haves two RS232 channels,
my little daughter her robot is based on an arduino mega 2560.
So, the next step is to make connection with the arduino mega.
You can find data here (sorry only in dutch for now)

http://www.marc-systems.be/ms_2018/webs ... ronics.htm

marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Re: RS232 serial terminal - WIN10 x64

Post by swhite »

Hi

I use Hercules from https://www.hw-group.com/software/hercu ... up-utility it is free and works well with the added benefit that it also supports TCP/IP.

Simon
Simon White
dCipher Computing
zefiro_flashparty
User
User
Posts: 74
Joined: Fri Mar 04, 2005 7:46 pm
Location: argentina

Re: RS232 serial terminal - WIN10 x64

Post by zefiro_flashparty »

ah :shock: I'm from Argentina, so everything is translated from Spanish to English.
In case some things do not make sense, it's the translator.
I program since I am 6 years old, with the old msx, ibms, etc, but certain things, basic routines, that escape my mental logic, and understanding, although somehow or other I always manage to make things go. my father was electronic, so I grew up with the first modems, making paquet radio, when there was no internet,
so with most things is more skill, than strength.

with respect to communication with the arduino,
the arduino sends me, by the com, accelerometer status data, and gyroscope, information, angles xyz, xyz acceleration, magnetometer, (it is very interesting the operation of the magnetometer, even if I put my hand, seems to capture my energy in the hand without touching it. ) also measured temperature, I built a loop to go see that data, but when I added the option to send to drive the engines, there began the problems and sometimes slowed down, if I restarted the program returned to receive that data, which it was not the arduino the problem I suppose, but my spaghetti code, I was trying to see the angle by the gyroscope, to do something similar to the old logo turtle.
since as I use dc motors, with reductive, I do not have much precision, but if I monitor the angle yes, my idea is to make it advance and generate a vector map in which then, remember and can go back exactly where the robot was traveling.
with some pathfinder.

I do not think I knew the SBC68000,
It's a 486? : D
there I looked at the marc system page,
Is that your robot? it's pretty.
mine is more artisan,
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)
zefiro_flashparty
User
User
Posts: 74
Joined: Fri Mar 04, 2005 7:46 pm
Location: argentina

Re: RS232 serial terminal - WIN10 x64

Post by zefiro_flashparty »

ohh I was looking at your page,
very good robot arm, I see that they are professional robots: D
congratulations, it's one of my dreams to make robots
robot arms, etc.
Good to have all the machines to be able to manufacture the pieces you want, I do not have anything at all, so it's a problem to build anything. I want a 3d printer, but here they are very expensive, so I'm still waiting.
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)
Post Reply