How to talk to notecard from my raspberrpi by using the USB port

Hello,
I want to use pi to automatically seeting some config for the notecard during the manufacturing stage.
and we have to use the USB port from notecard to talk with Pi.
I was able to open the USB serial port on pi when notecard connected to pi by usb interface.
but I cannot get any response from notecard.
any idea what would be the rig solution?
I think it should be regarded as a generic Serial port on Pi too, as on Windows computer, I can use a generic serial debug tools to send command and receive it

Because we want to use pi to do this work instead of computer during the manufacturing process.
so would be great if it works.
below is the simple debug code in python on raspberrypi

import serial
s = serial.Serial('/dev/ttyACM0',115200,timeout=2000)
if s.is_open:
    print("port opened")
    #s.write("trace +gpsmax".encode('utf-8'))
while True:
    print(s.read())

Hi @kevin and welcome to the Blues Wireless community!

There are a couple of things you should be aware of that may help:

  1. When you use diagnostic commands (i.e. a non-JSON command) with the Notecard, make sure you terminate them with a newline character \n.
  2. These non-JSON commands can differ from one version of the Notecard to another, which is why we don’t document them, but instead we recommend you always use supported JSON requests like {"req":"card.trace","trace":"+gpsmax"} instead.

What exactly are you trying to accomplish? It may be that we can find the right set of JSON requests for you from the Notecard API.

Thanks,
Rob

hey Roblauer,
Thanks for your reply on it.
I tried to use the json format and again, there is no response from notecard. I’m suspect whether it’s possible to even communicate with it by this method.
weird thing is I can even get it work by using the arduino serial tools.
so it should be pretty similar?

I want to set the APN and write the product config file to notecard in the production line.
And that process definitley need to be automatically.

@kevin,

Sorry - I wasn’t clear in my response above: all commands sent to the Notecard need to end with a newline character \n (JSON or not). Can you try that and let us know if it works?

Rob

hey RobLauer
Sorry still no response, my code is pretty simple and I thin it should works?

import serial
with serial.Serial('/dev/ttyACM0',115200,timeout=2000) as ser:
    ser.write(b'{"req":"card.trace","trace":"+gpsmax"}\n')
    while True:
        x = ser.read_until('\n')
        print(x)

Hey @RobLauer a quick update here. this piece of code seems working now.

with serial.Serial('/dev/ttyACM0',115200,timeout=20000) as ser:
    ser.write('{"req":"card.trace","trace":"+gpsmax"}\n'.encode())
    #ser.write('"trace +gpsmax"\n'.encode()) as ser:
    while True:
        x = ser.read_until()
        print(x)

I got the response from notecard now

pi@raspberrypi:~/shareFolder/github/rig_noteCard $ python3 serialPortTest.py
b’{“stop”:true,“trace”:“comm,sync,mdm,mdmmax,mem,gps,gpsmax”}\r\n’
which matches the log from a computer.

1 Like

Oh that’s great @kevin!

I was also going to suggest you consult the note-python library as there is serial interface code in there to take a look at.

Let us know if you run into any other issues!

Rob

hey @RobLauer I appreciate your help.
can you share me with another command in json format than stream out the log lively?
I once use sync-trace on computer. But seems that it cannot recieve any comomand that not in json format now

sad thing is this lib only suitable for a physical uart port but not the USB port from notecard,right?

You can enable a trace with {"req":"card.trace","mode":"on"} and disable it with "mode":"off". Is there something in particular you want to capture with your trace?

Also in note-python you can specify the serial port here (USB or UART should work fine): note-python/serial-example.py at 8d626e713a797f60cc6f3411dc8eb43f185e1669 · blues/note-python · GitHub

thanks @RobLauer I think I can play with it now.
there isn’s a particular thing that i want to capture, just want to make sure my python code works.