Opening serial.device unit 1 q 38400

3 posts / 0 new
Last post
Seventhwonder
Seventhwonder's picture
Offline
Last seen: 3 years 2 days ago
Joined: 2018-12-26 13:50
Opening serial.device unit 1 q 38400

Hi all

I am trying to serial.device unit 1 at 38400 baud and I am trying to send commands to it, but following code should shutdown A1222, but nothing happens. What am I doing wrong ?

(I used serial device example on AmigaOS4 Wiki)

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <exec/io.h>
  4. #include <devices/serial.h>
  5.  
  6. #include <proto/exec.h>
  7. #include <proto/dos.h>
  8.  
  9. int main()
  10. {
  11. struct MsgPort *SerialMP = IExec->AllocSysObjectTags(ASOT_PORT, TAG_END);
  12.  
  13. /* Create the message port */
  14. if (SerialMP != NULL)
  15. {
  16. /* Create the IORequest */
  17. struct IOExtSer *SerialIO = IExec->AllocSysObjectTags(ASOT_IOREQUEST,
  18. ASOIOR_ReplyPort, SerialMP,
  19. ASOIOR_Size, sizeof(struct IOExtSer),
  20. TAG_END);
  21.  
  22. if (SerialIO != NULL)
  23. {
  24. /* Open the serial device */
  25. if (IExec->OpenDevice(SERIALNAME, 1, (struct IORequest *)SerialIO, 0))
  26.  
  27. /* Inform user that it could not be opened */
  28. IDOS->Printf("Error: %s did not open\n",SERIALNAME);
  29. else
  30. {
  31.  
  32. SerialIO->io_Baud = 38400; /* set 38400 baud */
  33. SerialIO->IOSer.io_Length = 512;
  34. SerialIO->IOSer.io_Data = "#s\n";
  35. SerialIO->IOSer.io_Command = CMD_WRITE;
  36. if (IExec->DoIO((struct IORequest *)SerialIO)) /* execute write */
  37. IDOS->Printf("Write failed. Error - %ld\n", SerialIO->IOSer.io_Error);
  38.  
  39. /* Close the serial device */
  40. IDOS->Printf("Shutdown command given\n");
  41. IExec->CloseDevice((struct IORequest *)SerialIO);
  42. }
  43. /* Delete the IORequest */
  44. IExec->FreeSysObject(ASOT_IOREQUEST, SerialIO);
  45. }
  46. else
  47. /* Inform user that the IORequest could be created */
  48. IDOS->Printf("Error: Could create IORequest\n");
  49.  
  50. /* Delete the message port */
  51. IExec->FreeSysObject(ASOT_PORT, SerialMP);
  52. }
  53. else
  54. /* Inform user that the message port could not be created */
  55. IDOS->Printf("Error: Could not create message port\n");
  56.  
  57. return 0;
  58. }
hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: Opening serial.device unit 1 q 38400

It can be shut down that way? Well what a strange setup!

Maybe you gave it too many commands. You set the write length to 512, then send a string of 3 characters. You can set length to -1 for a arbitrary string.

You may need to use the SDCMD_SETPARAMS to set the baud rate.

https://wiki.amigaos.net/wiki/Serial_Device

jabirulo
jabirulo's picture
Offline
Last seen: 19 hours 35 min ago
Joined: 2013-05-30 00:53
Re: Opening serial.device unit 1 q 38400

On X5000 this sequence is used (for querying temp, "shutdown", if working, should be same but "#s\n"):

  1. ...
  2. port = IExec->AllocSysObject(ASOT_PORT, NULL);
  3. if(!port)
  4. {
  5. printf("No port\n");
  6. cleanup_stuff();
  7. }
  8. req = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size, sizeof(struct IOExtSer),
  9. ASOIOR_ReplyPort, port,
  10. TAG_DONE);
  11. if(!req)
  12. {
  13. printf("No Request\n");
  14. cleanup_stuff();
  15. }
  16.  
  17. //serialOpenConfig();
  18. err = IExec->OpenDevice("serial.device", 1, (struct IORequest*)req, 0);
  19. if(err)
  20. {
  21. dev = 0;
  22. printf("OpenDevice failed: %d\n", err);
  23. cleanup_stuff();
  24. }
  25.  
  26. // Set parameters to address MCU
  27. req->IOSer.io_Command = SDCMD_SETPARAMS;
  28. req->io_Baud = 38400; // 38400 Baud
  29. req->io_ReadLen = 8; // 8 bit data
  30. req->io_WriteLen = 8; // 8 bit data
  31. req->io_StopBits = 1; // 1 Stop bit
  32. req->io_SerFlags &= ~SERF_PARTY_ON; // No Parity
  33. req->io_SerFlags |= SERF_XDISABLED; // No Flow Control
  34. err = IExec->DoIO((struct IORequest*)req);
  35. if(err != IOERR_SUCCESS)
  36. {
  37. printf("Setting parameters to serial failed. Code: %d\n", err);
  38. cleanup_stuff();
  39. }
  40.  
  41. while(1)
  42. {
  43. // Temperatures
  44. req->IOSer.io_Length = 3;
  45. req->IOSer.io_Data = (APTR)"#t\n";//X5K_MCU_CMD_GET_TEMP;
  46. req->IOSer.io_Command = CMD_WRITE;
  47. IExec->DoIO((struct IORequest*)req);
  48. ...

BTW you can take a look at acpi.resource autodoc, maybe is valid for A1222 too.

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

Log in or register to post comments