mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Fixes SerialHelper when used with OS serial ports. (#411)
Also makes the SerialHelper API public so it can be used externally.
This commit is contained in:
committed by
Peter Johnson
parent
8e4afc95c7
commit
841f016017
@@ -20,7 +20,7 @@
|
||||
namespace hal {
|
||||
class SerialHelper {
|
||||
public:
|
||||
explicit SerialHelper(int32_t resourceHandle);
|
||||
SerialHelper();
|
||||
|
||||
std::string GetVISASerialPortName(HAL_SerialPort port, int32_t* status);
|
||||
std::string GetOSSerialPortName(HAL_SerialPort port, int32_t* status);
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "SerialHelper.h"
|
||||
#include "HAL/cpp/SerialHelper.h"
|
||||
#include "visa/visa.h"
|
||||
|
||||
static int32_t resourceManagerHandle;
|
||||
@@ -23,7 +23,7 @@ void HAL_InitializeSerialPort(HAL_SerialPort port, int32_t* status) {
|
||||
if (resourceManagerHandle == 0)
|
||||
viOpenDefaultRM(reinterpret_cast<ViSession*>(&resourceManagerHandle));
|
||||
|
||||
hal::SerialHelper serialHelper(resourceManagerHandle);
|
||||
hal::SerialHelper serialHelper;
|
||||
|
||||
portName = serialHelper.GetVISASerialPortName(port, status);
|
||||
|
||||
|
||||
@@ -5,29 +5,30 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "SerialHelper.h"
|
||||
#include "HAL/cpp/SerialHelper.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "../visa/visa.h"
|
||||
#include "HAL/Errors.h"
|
||||
#include "llvm/StringRef.h"
|
||||
#include "visa/visa.h"
|
||||
|
||||
constexpr const char* OnboardResourceVISA = "ASRL1::INSTR";
|
||||
constexpr const char* MxpResourceVISA = "ASRL2::INSTR";
|
||||
|
||||
constexpr const char* OnboardResourceOS = "ttyS0";
|
||||
constexpr const char* MxpResourceOS = "ttyS1";
|
||||
constexpr const char* OnboardResourceOS = "/dev/ttyS0";
|
||||
constexpr const char* MxpResourceOS = "/dev/ttyS1";
|
||||
|
||||
namespace hal {
|
||||
std::string SerialHelper::m_usbNames[2]{"", ""};
|
||||
|
||||
priority_mutex SerialHelper::m_nameMutex;
|
||||
|
||||
SerialHelper::SerialHelper(int32_t resourceHandle)
|
||||
: m_resourceHandle(resourceHandle) {}
|
||||
SerialHelper::SerialHelper() {
|
||||
viOpenDefaultRM(reinterpret_cast<ViSession*>(&m_resourceHandle));
|
||||
}
|
||||
|
||||
std::string SerialHelper::GetVISASerialPortName(HAL_SerialPort port,
|
||||
int32_t* status) {
|
||||
@@ -269,7 +270,8 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
|
||||
m_unsortedHubPath.emplace_back(
|
||||
llvm::StringRef{pathSplitVec[hubIndex - 2]});
|
||||
m_visaResource.emplace_back(desc);
|
||||
m_osResource.emplace_back(matchString);
|
||||
m_osResource.emplace_back(
|
||||
llvm::StringRef{osName}.split("(").second.split(")").first);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user