How to PID values to Device using RobotFramework via USB serial port

Hi,

Anyone here to resolve my issues

I have installed seriallibrary and I added COM port value and am able to see the list of ports in windows

I want to Send commands for some PID values to device via USB and need to read those reponse for the sended PID values.

Pls help me out how to send and read PID response from the device

Hi Dinesh,

The first step is to confirm you know exactly which com port your device is on, here is a guide for USB Serial devices in Window

Next unplug the USB serial port from the usb bus and plug it back into another port and check if it gets the same com port (Windows had a habit of making devices address change)

Once you know the port is reliably consistent, check the Port Settings (bits per second, etc) match the settings needed for your device under test.

Then try resending the commands again

Hopefully that will help you get it working,

Dave.

Hi Dave,

Thanks for the reply

Actually am going to use the same port for the testing. Below are the ports that i actually got while running robotframework automation

Here COM10 is the port where the device is connected to USB

For this COM port only am going to send PID values to the device via USB communication. Below are the sample code

*** Test Cases ***
Connect to a broker with default port and client id
SerialLibrary.Add Port COM10
SerialLibrary.Open Port COM10
#${port}= SerialLibrary.Get Current Port Locator
#Log ${port}
SerialLibrary.Port Should Be Open
${listofports}= SerialLibrary.List Com Port Names
Log ${listofports}

After this am not clear on how to send PID commands to the device and to read those success statuses if the PID values succeed

Pls let me know how to pass those PID values to the device

Hi Dinesh,

OK it looks like you’ve identified the port and it looks like the SerialLibrary has successfully opened that port. as SerialLibrary.Port Should Be Open passed, this is a good start.

Serial communication is actually quite simple, you send ASCII stings and get ASCII responses. I’m not sure what “PID commands” are, probably something unique to your device?

I know for dial up modems there was the AT command standard set of strings (most started with AT) that were used for configuring and instructing a modem how to dial numbers and connect to remote systems.

So guessing your PID commands are something similar then you would probably just send the PID commands with Write Data and read the response with one of the Read Data keywords

Based on the README and the help file, I’d try something basic like this:

*** Test Cases ***
Connect to a broker with default port and client id
    SerialLibrary.Add Port    COM10
    SerialLibrary.Open Port    COM10
    #${port}=    SerialLibrary.Get Current Port Locator
    #Log    ${port}
    SerialLibrary.Port Should Be Open    COM10
    #${listofports}=    SerialLibrary.List Com Port Names
    #Log    ${listofports}
    SerialLibrary.Write Data    ${PID_Command}    COM10
    ${response}=    SerialLibrary.Read All Data    COM10
    #Log    ${response}

Hope that helps,

Dave.

Hi Dave,

I tried with above code by adding value to write data as shown below

Variable
${PID_Command} 200

*** Test Cases ***
Connect to a broker with default port and client id
SerialLibrary.Add Port COM10
SerialLibrary.Open Port COM10
#${port}= SerialLibrary.Get Current Port Locator
#Log ${port}
SerialLibrary.Port Should Be Open COM10
#${listofports}= SerialLibrary.List Com Port Names
#Log ${listofports}
SerialLibrary.Write Data ${PID_Command} COM10
${response}= SerialLibrary.Read All Data COM10
#Log ${response}

I got the below error

Hi Dinesh,

Ah ok, change those two lines like this:

    SerialLibrary.Write Data    ${PID_Command}    port_locator=COM10
    ${response}=    SerialLibrary.Read All Data    port_locator=COM10

or like this will also probably work

    SerialLibrary.Write Data    ${PID_Command}
    ${response}=    SerialLibrary.Read All Data

Dave.

Hi Dave,

Thanks for the response

I have a doubt, currently am trying this use-case for the telematics device which has some commands like remote on,off etc. which has PID values like 201,250 etc. as mentioned earlier.

I passed those values as you have mentioned in the above codes where am not able to turn on or off the device but the code is getting pass

Do you have any idea about this

Hi Dinesh,

Unfortunately I doubt anyone here will be able to help you with that, you sent a command and got a response which you were able to read, so that’s a great start.

From here you are probably going to need to work with someone who knows the devices you are testing and what those responses mean.

You might need to send an end of line character or something like that, but that’s just a guess.

Dave.