void PortUX::PClose() { ClosePPDev(); CloseSerialPort(); CloseGPUSB(); CloseLXUSB(); }
void PortW32::PClose() { ClosePortTalk(); CloseSerialPort(); CloseGPUSB(); CloseLXUSB(); }
void RaceAnalyzerComm::ReadRuntime(RuntimeValues &values){ wxMutexLocker lock(_commMutex); try{ wxDateTime start = wxDateTime::UNow(); CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); wxString rsp = SendCommand(serialPort, "sample"); wxStringTokenizer tokenizer(rsp,";"); while (tokenizer.HasMoreTokens()){ wxString token = tokenizer.GetNextToken(); wxStringTokenizer subTokenizer(token,"="); if (subTokenizer.CountTokens() >= 2){ wxString name = subTokenizer.GetNextToken(); wxString value = subTokenizer.GetNextToken(); UnhideInnerTokens(value); if (value.StartsWith("\"") && value.EndsWith("\"")){ value = value.Left(value.Len() - 1); value = value.Right(value.Len() - 1); } values[name] = atof(value); } } } catch(CommException &e){ CloseSerialPort(); throw e; } }
int main() { int sfd; // serial port file descriptor int i = 0; // loop counter char RspBytes[MAX_RSP_CHARS]; // Response string int numBytes; // Open the serial port device associated with the HRMI if ((sfd = OpenSerialPort("/dev/cu.usbserial-A9003PDh")) == -1) { return(-1); } // Send a series of Get Heart Rate commands, each time requesting more history buffer // entries while (i++ < 33) { if (SendGetHeartRate(sfd, i) == 0) { printf("Error: SendGetHeartRate failed!\n"); break; } if (GetResponseString(sfd, RspBytes) == -1) { printf("Error: GetResponseString failed!\n"); break; } else { printf("Request %2d => %s\n", i, RspBytes); } sleep(1); } CloseSerialPort(sfd); }
wxString RaceAnalyzerComm::readScript(){ wxMutexLocker lock(_commMutex); wxString script = ""; int scriptPage = 0; int to = 0; CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); FlushReceiveBuffer(serialPort); while(!to){ //wxString cmd = wxString::Format("println(getScriptPage(%d))",scriptPage++); wxString cmd = wxString::Format("readScriptPage %d",scriptPage++); wxString buffer = SendCommand(serialPort, cmd); wxString scriptFrag = GetParam(buffer,"script", true); VERBOSE(FMT("escaped: %s", scriptFrag.ToAscii())); Unescape(scriptFrag); VERBOSE(FMT("unescaped: %s", scriptFrag.ToAscii())); size_t scriptFragmentLen = scriptFrag.Length(); if (scriptFragmentLen > 0 ) script+=scriptFrag; //the last page is a 'partial page' if (scriptFragmentLen < SCRIPT_PAGE_LENGTH ) break; } CloseSerialPort(); if (to){ throw CommException(CommException::COMM_TIMEOUT); } return script; }
void tty_shutdown(void *ctx0) { tty_ctx *ctx; ctx = ctx0; CloseSerialPort(ctx->fd); fclose(ctx->fp); free(ctx); }
void RaceAnalyzerComm::readConfig(RaceCaptureConfig *config,RaceAnalyzerCommCallback *callback){ try{ wxDateTime start = wxDateTime::UNow(); int updateCount = 0; CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); updateWriteConfigPct(updateCount, callback); readGpsConfig(&config->gpsConfig); updateWriteConfigPct(++updateCount, callback); readGpsTargetConfig(&config->gpsConfig); updateWriteConfigPct(++updateCount, callback); readAnalogConfig(config->analogConfigs); updateCount += CONFIG_ANALOG_CHANNELS; updateWriteConfigPct(updateCount, callback); readTimerConfig(config->timerConfigs); updateCount += CONFIG_TIMER_CHANNELS; updateWriteConfigPct(updateCount, callback); readAccelConfig(config->accelConfigs); updateCount += CONFIG_ACCEL_CHANNELS; updateWriteConfigPct(updateCount, callback); readAnalogPulseConfig(config->pwmConfigs); updateCount += CONFIG_ANALOG_PULSE_CHANNELS; updateWriteConfigPct(updateCount, callback); readGpioConfig(config->gpioConfigs); updateCount += CONFIG_GPIO_CHANNELS; updateWriteConfigPct(updateCount, callback); readConnectivityConfig(&config->connectivityConfig); updateWriteConfigPct(++updateCount,callback); config->luaScript = readScript(); updateWriteConfigPct(++updateCount,callback); wxTimeSpan dur = wxDateTime::UNow() - start; VERBOSE(FMT("get config in %f",dur.GetMilliseconds().ToDouble())); callback->ReadConfigComplete(true,""); } catch(CommException &e){ callback->ReadConfigComplete(false, e.GetErrorMessage()); } CloseSerialPort(); }
BOOL CloseComPort() { if(gComPortInfo.bIsOpen == FALSE) { return TRUE; } if(CloseSerialPort(gComPortInfo.ComID) == FALSE) { return FALSE; } gComPortInfo.bIsOpen = FALSE; EnableComboBox(TRUE); return TRUE; }
void RaceAnalyzerComm::flashCurrentConfig(){ try{ wxDateTime start = wxDateTime::UNow(); CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); wxString cmd = "flashLoggerCfg"; wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); wxTimeSpan dur = wxDateTime::UNow() - start; VERBOSE(FMT("flash config in %f",dur.GetMilliseconds().ToDouble())); } catch(CommException &e){ VERBOSE(FMT("Error during flash: %s", e.GetErrorMessage())); } CloseSerialPort(); }
void RaceAnalyzerComm::calibrateAccelZero(){ wxMutexLocker lock(_commMutex); try{ wxDateTime start = wxDateTime::UNow(); CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); wxString cmd = "calibrateAccelZero"; wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); wxTimeSpan dur = wxDateTime::UNow() - start; VERBOSE(FMT("calibrateAccelZero in %f",dur.GetMilliseconds().ToDouble())); } catch(CommException &e){ VERBOSE(FMT("Error during calibrateAccelZero: %s", e.GetErrorMessage())); throw e; } CloseSerialPort(); }
void RaceAnalyzerComm::writeScript(wxString &script){ wxMutexLocker lock(_commMutex); size_t index = 0; int page,to; page = 0; to = 0; size_t length = script.Length(); CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); while(index < length && page < SCRIPT_PAGES && !to){ wxString scriptFragment; if (index + SCRIPT_PAGE_LENGTH > length){ scriptFragment = script.Mid(index); }else{ scriptFragment = script.Mid(index, SCRIPT_PAGE_LENGTH); } Escape(scriptFragment); //wxString cmd = wxString::Format("updateScriptPage(%d,\"%s\")", page,data.ToAscii()); wxString cmd = wxString::Format("writeScriptPage %d %s",page,scriptFragment.ToAscii()); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); page++; index += SCRIPT_PAGE_LENGTH; } //did we write fewer than the max number of script pages? //note we're subtracting script pages by one to account for integer divide truncation if ((length / SCRIPT_PAGE_LENGTH) < SCRIPT_PAGES - 1 ){ //write a null to the next page wxString cmd = wxString::Format("writeScriptPage %d",page); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); } CloseSerialPort(); if (to){ throw CommException(CommException::COMM_TIMEOUT); } }
wxString RaceAnalyzerComm::GetLogfile(){ wxMutexLocker lock(_commMutex); wxString logfileData; try{ CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); wxString rsp = SendCommand(serialPort, "{\"getLogfile\":0}",1000); try{ if (rsp.Len() > 0 ){ Object root = ParseJSON(rsp); const String &val = root["logfile"]; logfileData = val.Value(); } } catch (const Exception& e){ ERROR(FMT("could not parse logfile response: %s",rsp)); } } catch(CommException &e){ CloseSerialPort(); throw e; } return logfileData; }
void closeSerial(int handle) { CloseSerialPort(handle); }
RaceAnalyzerComm::~RaceAnalyzerComm(){ CloseSerialPort(); }
//================================================================================================== void TestDialog_2::OnBnClickedButton4() { CloseSerialPort(); }
int End_joypad(void) { CloseSerialPort(fileDescriptor); printf("Modem port closed.\n"); }
void RaceAnalyzerComm::writeConfig(RaceCaptureConfig *config, RaceAnalyzerCommCallback * callback){ try{ wxDateTime start = wxDateTime::UNow(); CComm *serialPort = GetSerialPort(); if (NULL==serialPort) throw CommException(CommException::OPEN_PORT_FAILED); int updateCount = 0; for (int i = 0; i < CONFIG_ANALOG_CHANNELS;i++){ AnalogConfig &cfg = config->analogConfigs[i]; wxString cmd = "setAnalogCfg"; cmd = AppendIntParam(cmd, i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.loggingPrecision); cmd = AppendIntParam(cmd, cfg.scalingMode); cmd = AppendFloatParam(cmd, cfg.linearScaling); ScalingMap &map = (cfg.scalingMap); for (int m=0; m < CONFIG_ANALOG_SCALING_BINS;m++){ cmd = AppendIntParam(cmd, map.rawValues[m]); } for (int m=0; m < CONFIG_ANALOG_SCALING_BINS;m++){ cmd = AppendFloatParam(cmd, map.scaledValue[m]); } wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_TIMER_CHANNELS; i++){ TimerConfig &cfg = config->timerConfigs[i]; wxString cmd = "setTimerCfg"; cmd = AppendIntParam(cmd, i); AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.loggingPrecision); cmd = AppendIntParam(cmd, cfg.slowTimerEnabled); cmd = AppendIntParam(cmd, cfg.mode); cmd = AppendIntParam(cmd, cfg.pulsePerRev); cmd = AppendIntParam(cmd, cfg.timerDivider); cmd = AppendIntParam(cmd, cfg.scaling); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_ACCEL_CHANNELS; i++){ AccelConfig &cfg = config->accelConfigs[i]; wxString cmd = "setAccelCfg"; cmd = AppendIntParam(cmd, i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.mode); cmd = AppendIntParam(cmd, cfg.channel); cmd = AppendIntParam(cmd, cfg.zeroValue); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_ANALOG_PULSE_CHANNELS; i++){ PwmConfig &cfg = config->pwmConfigs[i]; wxString cmd = "setPwmCfg"; cmd = AppendIntParam(cmd, i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.loggingPrecision); cmd = AppendIntParam(cmd, cfg.outputMode); cmd = AppendIntParam(cmd, cfg.loggingMode); cmd = AppendIntParam(cmd, cfg.startupDutyCycle); cmd = AppendIntParam(cmd, cfg.startupPeriod); cmd = AppendFloatParam(cmd, cfg.voltageScaling); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } for (int i = 0; i < CONFIG_GPIO_CHANNELS; i++){ GpioConfig &cfg = config->gpioConfigs[i]; wxString cmd = "setGpioCfg"; cmd = AppendIntParam(cmd,i); cmd = AppendChannelConfig(cmd, cfg.channelConfig); cmd = AppendIntParam(cmd, cfg.mode); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } { GpsConfig &cfg = config->gpsConfig; { wxString cmd = "setGpsCfg"; cmd = AppendIntParam(cmd, cfg.gpsInstalled); cmd = AppendChannelConfig(cmd, cfg.latitudeCfg); cmd = AppendChannelConfig(cmd, cfg.longitudeCfg); cmd = AppendChannelConfig(cmd, cfg.speedCfg); cmd = AppendChannelConfig(cmd, cfg.timeCfg); cmd = AppendChannelConfig(cmd, cfg.satellitesCfg); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } { wxString cmd = "setStartFinishCfg"; cmd = AppendChannelConfig(cmd, cfg.lapCountCfg); cmd = AppendChannelConfig(cmd, cfg.lapTimeCfg); cmd = AppendChannelConfig(cmd, cfg.splitTimeCfg); cmd = AppendFloatParam(cmd, cfg.startFinishTarget.latitude); cmd = AppendFloatParam(cmd, cfg.startFinishTarget.longitude); cmd = AppendFloatParam(cmd, cfg.startFinishTarget.targetRadius); cmd = AppendFloatParam(cmd, cfg.splitTarget.latitude); cmd = AppendFloatParam(cmd, cfg.splitTarget.longitude); cmd = AppendFloatParam(cmd, cfg.splitTarget.targetRadius); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } } { ConnectivityConfig &cfg = config->connectivityConfig; wxString cmd = "setOutputCfg"; cmd = AppendIntParam(cmd, cfg.sdLoggingMode); cmd = AppendIntParam(cmd, cfg.connectivityMode); cmd = AppendUIntParam(cmd, cfg.p2pConfig.destinationAddrHigh); cmd = AppendUIntParam(cmd, cfg.p2pConfig.destinationAddrLow); cmd = AppendStringParam(cmd, cfg.telemetryConfig.telemetryServer); cmd = AppendStringParam(cmd, cfg.telemetryConfig.telemetryDeviceId); wxString result = SendCommand(serialPort, cmd); CheckThrowResult(result); cmd = "setCellCfg"; cmd = AppendStringParam(cmd, cfg.cellularConfig.apnHost); cmd = AppendStringParam(cmd, cfg.cellularConfig.apnUser); cmd = AppendStringParam(cmd, cfg.cellularConfig.apnPass); result = SendCommand(serialPort, cmd); CheckThrowResult(result); updateWriteConfigPct(++updateCount,callback); } { writeScript(config->luaScript); updateWriteConfigPct(++updateCount,callback); } wxTimeSpan dur = wxDateTime::UNow() - start; VERBOSE(FMT("write config in %f",dur.GetMilliseconds().ToDouble())); callback->WriteConfigComplete(true,""); } catch(CommException &e){ callback->WriteConfigComplete(false, e.GetErrorMessage()); } CloseSerialPort(); }