| 57 | } |
| 58 | |
| 59 | int LibFTDISerial::open_serial_port () |
| 60 | { |
| 61 | if (!lib_init) |
| 62 | { |
| 63 | // failed to init libftdi; at least check the port name |
| 64 | if (description.size () < 4) |
| 65 | { |
| 66 | return SerialExitCodes::PORT_NAME_ERROR; |
| 67 | } |
| 68 | if (description[0] == '/' || description[1] != ':') |
| 69 | { |
| 70 | return SerialExitCodes::PORT_NAME_ERROR; |
| 71 | } |
| 72 | return SerialExitCodes::OPEN_PORT_ERROR; |
| 73 | } |
| 74 | // https://www.intra2net.com/en/developer/libftdi/documentation/ftdi_8c.html#aae805b82251a61dae46b98345cd84d5c |
| 75 | last_result = ftdi_usb_open_string (&ftdi, description.c_str ()); |
| 76 | if (last_result == 0) |
| 77 | { |
| 78 | port_open = true; |
| 79 | return (int)SerialExitCodes::OK; |
| 80 | } |
| 81 | log_error ("open_serial_port ()"); |
| 82 | switch (last_result) |
| 83 | { |
| 84 | case -10: |
| 85 | return (int)SerialExitCodes::CLOSE_ERROR; |
| 86 | case -11: |
| 87 | return (int)SerialExitCodes::PORT_NAME_ERROR; |
| 88 | default: |
| 89 | return (int)SerialExitCodes::OPEN_PORT_ERROR; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | bool LibFTDISerial::is_port_open () |
| 94 | { |
nothing calls this directly
no outgoing calls
no test coverage detected