SerialConnect does not stop sending Status Requests

Having issue sending string to COM port.
To diagnose, I downloaded a Serial Port Monitor (from Electronic Team Inc.)
I am struggling to connect to a device. I am connecting to a Teknic Clearcore (ETHERNET/IP® INDUSTRIAL I/O AND MOTION CONTROLLER).
This device (ClearCore) is a servo motor controller with additional Inputs/Outputs.
This device (ClearCore) is programmed in C++, but you can use an Arduino Wrapper.
I downloaded Arduino IDE and programmed the ClearCore. To upload the program to the Clearcore, you use a USB cable.
Once the ClearCore is programmed, in normal usage it can be controlled using either the USB connection, An Ethernet cable connection, or an RS232 connection. I am choosing to use the USB connection.

I programmed just 3 things in Arduino IDE that if sent to Clearcore will control motor etc…

  1. Receive command to move motor a certain amount (in this case ticks of the encoder) with a command like “Move 40000”
  2. Turn on or off an Output with command like “IO31” (This will turn I/O #3 ON)
  3. Send string when for example, motor reached it’s destination (In this case “Motor Done”)

The Arduino IDE has a “Serial Monitor” that you can use to communicate to a port, when I open the “Serial Monitor” you can send strings. If I send “Move 30000”, physically the motor moves incrementally to a new position 30000 ticks of encoder away from previous one (Say 25 rotations of the shaft) The Outputs also work, as well as the strings coming back from the ClearCore. I’ve attached a picture of the Serial Port Monitor reading everything for that port. For the Move command it takes 18 transactions and stops and waits for new command.

With the Xojo application, something is making the communication between the computer and the ClearCore to continue without termination for thousands of lines (until I close the connection) So it seems it is not connecting properly and therefore I can’t send a string like “Move 25000”. I’ve attached a picture of the Serial Port Monitor reading everything for that port, and as you can see it goes into thousands of Up Down transmissions.
I created a button to just do 2 things, and still the communications just cycles endlessly as shown in picture of Serial Port Monitor. the 2 lines of code for that are :
//There is “COM4” on DevicePopupMenu, which is correct and does start transmitting
SerialConnection2.Device = SerialDevice.At(DevicesPopupMenu.SelectedRowIndex)
//even this simple 2 lines of code, results in an endless Status Requests going back and forth between computer and Device

I also have added pictures of the Xojo code etc.
Not sure if string encoding is also a problem

Pictures can be found here

I hope it is a simple problem, but I really need help

I can’t load your project because it’s incompatible with the Xojo version I use. You’ve shown your code for connecting/disconnecting but none of the code that does actual communications as far as I can see. If you post that code here I’ll be glad to take a look at it.

Here is an example of code behind a button press event

SerialConnection2.Write(“Move 40000”)

Also, not sure if it makes a difference but monitoring COM4, when using Arduino Serial Monitor that I can send “Move 40000” and the device works properly by rotating the motor, the transmission looks like this:
28336793 16/01/2023 12:47:57 IRP_MJ_WRITE DOWN 4d 6f 76 65 20 34 30 30 30 30 0a Move 40000. 11 11 COM4
Data from above is “4d 6f 76 65 20 34 30 30 30 30 0a”
Data (chars) from above is “Move 40000.”

When sending command from Xojo, the motor doesn’t move and the transmission looks like this:
28336746 16/01/2023 12:46:48 IRP_MJ_WRITE DOWN 4d 6f 76 65 20 34 30 30 30 30 2e Move 40000. 11 11 COM4
Data from above is “4d 6f 76 65 20 34 30 30 30 30 2e”
Data (chars) from above is “Move 40000.”

So there is a slight difference at the end. The good transmission ends with “0a” the Xojo with “2e”
“0a” is linefeed

Not sure how important that is, because the real issue is the connection not standing still to even allow me to send it a command through Xojo SerailConnect

I’ve done a lot of projects with SerialConnection and have never seen it send something when not explicitly told to.

I notice that you’ve enabled both hardware handshaking and XON flow control - normally you’d use only one of these. XON is pretty rare in my experience, try turning that off.

Hi Julia. I turn it off and the same results. I have noticed that it seems Xojo is not sending some termination chr. I’ve been trying several things and using the port monitor to see what is happening. Currently if send command, the device pauses, as if waiting for something to tell it that the transmission is finished.

Arduino is sending “Move 4000” + LF.

Your program is sending “Move 4000.”, which is why it ends with 0x2E (period) instead of LF (0x0A).

Maybe you should write “Move 4000”+ChrB(0x0A) to your SerialConnection.

I understand, but how do you send the linefeed after the string?

Ha, I edited my post while you were replying :slight_smile:

Tried this line (By the way, “mo 40000” means Motor 0 move 40000 ticks, Same as Move 40000)

SerailConnection2.Write(“m0 40000” + ChrB(0x0A))

Can’t run due to syntax error

SerialConnection2.Write("Move 4000"+ChrB(0x0A))

Oh, maybe Xojo changed the syntax… ChrByte now. Regular Chr(0x0A) will probably work, too.

Oh, and it should be &h0A, not 0x0A. Confusing my languages, sorry.

Or just ChrByte(10), lol.

Hi Julia, really appreciate your help. I have to go to the main problem, then worry about the syntax.
As explained in previous posts and in pictures, when I connect to ClearCore device using Arduino Serial Port and I send comands (Like “Move 40000”) the ClearCore works just fine. If I look at traffic on serial port, I can see the regular and controlled communication between the Arduino Seral Port and the ClearCore. When I try do do the same with a Xojo app, as soon as I connect (e.g. SerialConnection2.Connect) The port opens and then the traffic contains mainly status requests and it goes on continuously, so there is no chance to even send a command (like “Move 40000”) Please see movie you can download from here Dropbox - IMG_3250.MOV - Simplify your life

Some random debugging ideas:

  • Use Xojo’s search function to find every occurrance of “.write” in your code, and put a breakpoint at each.
  • Add a DataReceived event to your SerialConnection and breakpoint there to see what if anything the device is sending to you.
  • Put an oscilloscope or logic analyzer on RX, TX, CTS, and RTS to see the actual data going back and forth.
  • Step through your code to find out exactly when the unexpected transmissions start.

Seems weird that simply opening the port causes transmissions to start, especially if your code is not executing Writes.

Make sure you don’t have the Arduino or any other tool using the port. You can’t have the port being open anywhere else other than xojo for it to work. Also after you Open the the port in xojo doesn’t mean it works, Serial requires the right settings, use a tool that you can test these with some tool was made with xojo not sure the name, but it uses the same class and has all the settings.

Make sure you have the Baud, Paring, Stop bits etc all correctly set.
In the DataReceived event add your data to a buffer, then use a (low period = 10) Timer to read from the buffer.