{"action":"created","issue":{"url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/4233","repository_url":"https://api.github.com/repos/MarlinFirmware/Marlin","labels_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/4233/labels{/name}","comments_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/4233/comments","events_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/4233/events","html_url":"https://github.com/MarlinFirmware/Marlin/issues/4233","id":164217622,"number":4233,"title":"apply a new serial port in Marlin Firmware","user":{"login":"youngyhw","id":18223257,"avatar_url":"https://avatars.githubusercontent.com/u/18223257?v=3","gravatar_id":"","url":"https://api.github.com/users/youngyhw","html_url":"https://github.com/youngyhw","followers_url":"https://api.github.com/users/youngyhw/followers","following_url":"https://api.github.com/users/youngyhw/following{/other_user}","gists_url":"https://api.github.com/users/youngyhw/gists{/gist_id}","starred_url":"https://api.github.com/users/youngyhw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youngyhw/subscriptions","organizations_url":"https://api.github.com/users/youngyhw/orgs","repos_url":"https://api.github.com/users/youngyhw/repos","events_url":"https://api.github.com/users/youngyhw/events{/privacy}","received_events_url":"https://api.github.com/users/youngyhw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/MarlinFirmware/Marlin/labels/Discussion:%20Developers","name":"Discussion: Developers","color":"FF77AA"},{"url":"https://api.github.com/repos/MarlinFirmware/Marlin/labels/Needs:%20Discussion","name":"Needs: Discussion","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":30,"created_at":"2016-07-07T02:40:49Z","updated_at":"2016-08-03T22:49:05Z","closed_at":"2016-07-15T09:21:58Z","body":"Hi, guys. Not long before, I needed a new serial port to communicate with Marlin Firmware, but, it seems that a new serial port like Serial1, Serial2 can not be used in any .cpp or .h files except .ino file.\r\n\r\nYou know what I am trying to tell you? Ah ha, yes, there is a way to apply a new serial port. \r\nWe just need to add a new .ino file edited in Arduino ( I debug those code in Arduino ), then add what you want the new serial port to do. Over.\r\n\r\nI hope it can help you!\r\n\r\nFollowing is my code segment:\r\n```cpp\r\nString comdata = \"\";\r\nString cmd = \"\";\r\nchar usart_received_char;\r\nunsigned char state = 0;\r\nbool Cmd_completed = false;\r\n\r\nvoid cmd_execute();\r\n\r\n/*\r\n  SerialEvent occurs whenever a new data comes in the\r\n  hardware serial RX.  This routine is run between each\r\n  time loop() runs, so using delay inside loop can delay\r\n  response.  Multiple bytes of data may be available.\r\n*/\r\nvoid serialEvent2() {\r\n  while (Serial2.available()) {\r\n    // get the new byte:\r\n    char inChar = (char)Serial2.read();\r\n\r\n    switch (state) {\r\n      case 0:\r\n        if (inChar == '#') state = 1;\r\n        break;\r\n      case 1:\r\n        if (inChar == '$') {\r\n          cmd = comdata;\r\n          comdata = \"\";\r\n          Cmd_completed = true;\r\n          cmd_excute();\r\n          state = 0;\r\n        }\r\n        else {\r\n          comdata += inChar;\r\n        }\r\n        break;\r\n      default:\r\n        break;\r\n    }\r\n\r\n  }\r\n}\r\n\r\nvoid cmd_execute() {\r\n  if ( cmd == \"AskForFileList\") {\r\n    Serial2.print(\"#TA100/230\\tTB56/230\\tTC110/112\\tPS4\\tPP56\\tPT02:43:24\\tFNmonkey.gco\\t$\");\r\n  }\r\n  if ( cmd == \"GoOnPrinting1\") {\r\n    ;//断点打印\r\n  }\r\n  if ( cmd == \"GoOnPrinting2\") {\r\n   ;//暂停后继续打印\r\n  }\r\n  if ( cmd == \"PrintingCanceled\") { }\r\n  if ( cmd == \"GetInfo\") { }\r\n  if ( cmd == \"RefuseInfo\") { }\r\n  if ( cmd == \"StartPrinting\") { }\r\n  if ( cmd == \"PausePrinting\") { }\r\n  if ( cmd == \"ReplaceMaterial\") { }\r\n  if ( cmd == \"NozzleHeating225\") { }\r\n  if ( cmd == \"BedHeating225\") { }\r\n  if ( cmd == \"XHome\") { }\r\n  if ( cmd == \"YHome\") { }\r\n  if ( cmd == \"ZHome\") { }\r\n  if ( cmd == \"AllHome\") { }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/comments/237399187","html_url":"https://github.com/MarlinFirmware/Marlin/issues/4233#issuecomment-237399187","issue_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/4233","id":237399187,"user":{"login":"thinkyhead","id":698003,"avatar_url":"https://avatars.githubusercontent.com/u/698003?v=3","gravatar_id":"","url":"https://api.github.com/users/thinkyhead","html_url":"https://github.com/thinkyhead","followers_url":"https://api.github.com/users/thinkyhead/followers","following_url":"https://api.github.com/users/thinkyhead/following{/other_user}","gists_url":"https://api.github.com/users/thinkyhead/gists{/gist_id}","starred_url":"https://api.github.com/users/thinkyhead/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thinkyhead/subscriptions","organizations_url":"https://api.github.com/users/thinkyhead/orgs","repos_url":"https://api.github.com/users/thinkyhead/repos","events_url":"https://api.github.com/users/thinkyhead/events{/privacy}","received_events_url":"https://api.github.com/users/thinkyhead/received_events","type":"User","site_admin":false},"created_at":"2016-08-03T22:49:05Z","updated_at":"2016-08-03T22:49:05Z","body":"> I bet you need two pins.\r\n\r\n@AnHardt Seems that way.\r\n\r\n> TTL to RS485 Module\r\n\r\nDo you think this is absolutely needed? I'm happy to do SPI or i2c or whatever else, but the board I'm trying to connect has on-board (half-duplex) RS485, so as long as I can wire an Rx and Tx I should be able to do communication. I just need to pick the best library to implement the port.\r\n\r\n> but SerialPort2 not … GPIOs with certain purpose\r\n\r\n@youngyhw Understand that I am a beginner. I would very much like to see a working implementation of a second serial port attached to a RAMPS (or MKS Gen) board and communicating two ways with a separate board over RS485."}}
{"actor":{"display_login":"thinkyhead"}}