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

**URL:** <https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186>\
**Category:** Robot Framework\
**Created:** [8 September 2023 15:53 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186 "2023-09-08T15:53:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dinesh](https://forum.robotframework.org/u/Dinesh)\
**Post date:** [8 September 2023 15:53 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/1 "2023-09-08T15:53:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [9 September 2023 00:20 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/2 "2023-09-09T00:20:07Z")

</div>

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](https://kb.plugable.com/serial-adapter/how-to-change-the-com-port-for-a-usb-serial-adapter-on-windows-7,-8,-81,-and-10)

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.

---

<div class="post-metadata">

**Author:** ![Dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dinesh](https://forum.robotframework.org/u/Dinesh)\
**Post date:** [9 September 2023 04:47 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/3 "2023-09-09T04:47:57Z")

</div>

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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/4/40b367af640348af20a55187b1097374968793d1.png)

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [9 September 2023 08:51 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/4 "2023-09-09T08:51:29Z")

</div>

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](https://en.wikipedia.org/wiki/Hayes_AT_command_set) 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](https://github.com/whosaysni/robotframework-seriallibrary/blob/develop/README.rst) and the help file, I’d try something basic like this:

```python
***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.

---

<div class="post-metadata">

**Author:** ![Dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dinesh](https://forum.robotframework.org/u/Dinesh)\
**Post date:** [9 September 2023 13:55 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/5 "2023-09-09T13:55:41Z")

</div>

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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/5/5e9de53a1fc27f0c86c8d6e3cb148df21a583dd8.png)

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [9 September 2023 14:19 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/6 "2023-09-09T14:19:47Z")

</div>

Hi Dinesh,

Ah ok, change those two lines like this:

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

```

or like this will also probably work

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

```

Dave.

---

<div class="post-metadata">

**Author:** ![Dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dinesh](https://forum.robotframework.org/u/Dinesh)\
**Post date:** [10 September 2023 06:55 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/7 "2023-09-10T06:55:34Z")

</div>

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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/8/823fadaf5570c860fea34ae9207d7c7aa3984f70.png)

Do you have any idea about this

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [10 September 2023 08:24 UTC](https://forum.robotframework.org/t/how-to-pid-values-to-device-using-robotframework-via-usb-serial-port/6186/8 "2023-09-10T08:24:17Z")

</div>

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.
