Announcement

Collapse
No announcement yet.

serial port on AMS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • serial port on AMS

    hello all,
    so i'm trying to recieve date from my serial port ( COM4 )
    to send and recieve sms for exemple,
    i'v tested my hardwer using putty and it work find
    now i'm looking to use my AMS projet to recieve my data,
    how could i do that

  • #2
    Apparently you can use native Lua functions to do this;
    Code:
    os.execute[[mode COM4: baud=9600 parity=N data=8 stop=1]]
    let's you set up the COM port

    Code:
    local com = io.open("COM4:","rb")
    local data = com:read(1024) -- read 1024 bytes from COM4
    Does that do something for you?
    I've never interacted with COM through Lua, I always did so through C++ or C.
    Bas Groothedde
    Imagine Programming :: Blog

    AMS8 Plugins
    IMXLH Compiler

    Comment


    • #3
      i think we could connect to serial port with thoses codes,
      but how we can send and recieve command ?
      for exemple if we send an AT command, we will recieve ""OK""
      how we can recieve the "Ok" in my variable

      Comment


      • #4
        so i try this methode, and i can now send command to my serial device (usb gsm modem)
        now is how to recieve the answer of my device ( should be "OK" when i send "AT" )

        code
        Code:
        port = "com4";
        baud = 9600
        
        os.execute("powershell $port= new-Object System.IO.Ports.SerialPort "..port..","..baud..",None,8,one;$port.open();$por t.close();")
        
        serial = io.open(port,"w")
        serial:write("AT")
        serial:write("\n")
        serial:flush()
        serial:close()

        Comment


        • #5
          Have you tried serial:read at all? After :flush there might be data available.
          Bas Groothedde
          Imagine Programming :: Blog

          AMS8 Plugins
          IMXLH Compiler

          Comment


          • #6
            yes i try that, nut i think it's got an infinity loop because my app doesn't respond
            Code:
            local file="COM4"
            local fd_r=assert(io.open(file,"r"))
            local fd_w=assert(io.open(file,"w"))
            fd_w:setvbuf("no") --no buffering
            fd_r:flush()
            fd_w:flush()
            
            cmd="at\r"
            fd_w:write(cmd)
            fd_w:flush()
            fd_r:flush()
            r = fd_r:read("*all")
            
            fd_w:close()
            fd_r:close()
            
            Input.SetText("Input1", r);

            Comment


            • #7
              With i/o I never really use `:read("*all")` because it might just wait for data to be available on the buffer.
              It might be smarter to read a chunk of the size you expect. Let's say you send a command and know you'll get i.e. a +OK, use `fd_r:read(3)`

              It's difficult for me to make an example for you as I probably don't have the hardware you're testing with.
              Bas Groothedde
              Imagine Programming :: Blog

              AMS8 Plugins
              IMXLH Compiler

              Comment


              • #8
                thank you for answer sir,
                i try as u said, but it doesn't work too,
                it's got an infinity loop because my app doesn't respond

                Comment


                • #9
                  im interested with this project.. i am planing to buy ESP12 and want to build simple home on and off relay for the lights..

                  Comment

                  Working...
                  X