Re: Read/Write USB

new topic     » goto parent     » topic index » view thread      » older message » newer message

If the Arduino is connected through a USB/serial adapter, then Jacques Deschênes's serial library will fit the job. I used it this way.

include serial.ew 
 
atom hCom1 
 
constant MAXDWORD=#FFFFFFFF 
 
------------------------------------------------------------------------------ 
 
public function serialOpen(integer port ,sequence baud ,sequence parity , 
                           sequence numBits ,sequence numStop ,sequence control) 
  hCom1 = serial_open(port) 
  if hCom1 < 0 then 
    printf(1,"Error opening port %d.\n\n",port) 
    return 0 
  else 
    -- http://msdn.microsoft.com/en-us/library/aa363190%28v=VS.85%29.aspx 
    -- A value of MAXDWORD, combined with zero values for both the ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier  members, 
    -- specifies that the read operation is to return immediately with the bytes that have already been received, 
    -- even if no bytes have been received. 
    SetCommTimeouts(hCom1,{MAXDWORD,0,0,0,0}) 
    SetCommState(hCom1, "baud:"&baud&";parity:"&parity&";bits:"&numBits& 
                        ";stop:"&numStop&";control:"&control) 
    PurgeComm(hCom1,PURGE_RXCLEAR) 
    --puts(1, "serialOpen: port set at baud: "&baud&", parity: "&parity&", bits: "&numBits& 
    --                    ", stop bits: "&numStop&", flow control: "&control) 
    return 1 
  end if 
--  return hCom1 
end function 
 
------------------------------------------------------------------------------ 
 
public procedure serialClose() 
  serial_close(hCom1) 
  --logMsg("serialClose: connection closed") 
end procedure 
 
------------------------------------------------------------------------------ 
 
public procedure serialSend(object x) 
  serial_puts(hCom1, x) 
end procedure 
 
------------------------------------------------------------------------------ 
 
public function serialReceive() 
  return serial_getc(hCom1) 
end function 
 

Jean-Marc

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu