154 lines
4.1 KiB
C++
154 lines
4.1 KiB
C++
#include "canusb.h"
|
|
#include "ui_canusb.h"
|
|
#include <QFileDialog>
|
|
#include <QLineEdit>
|
|
#include <QDebug>
|
|
#include <QTime>
|
|
#include "ui_send_cmd.h"
|
|
#include "ProjectSettings.h"
|
|
|
|
CanUsb *target;
|
|
|
|
CB_FLAGS cb_flags;
|
|
CanUsb::CanUsb(QWidget *parent)
|
|
: QWidget(parent)
|
|
, ui(new Ui::CanUsb)
|
|
{
|
|
ui->setupUi(this);
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
init();
|
|
}
|
|
|
|
CanUsb::~CanUsb()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void CanUsb::init()
|
|
{
|
|
target=this;
|
|
Refresh();
|
|
ui->dataBitsBox->setEditText("1CE0E1");
|
|
}
|
|
|
|
unsigned CanUsb::div_up(unsigned x, unsigned y)
|
|
{
|
|
return (x - 1) / y + 1;
|
|
}
|
|
|
|
void CanUsb::Refresh()
|
|
{
|
|
ui->serialPortInfoListBox->setDisabled(TRUE);
|
|
int count = SlCan_GetDeviceCount();
|
|
QString currPort = ui->serialPortInfoListBox->currentText();
|
|
ui->serialPortInfoListBox->clear();
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
HSLCAN device = SlCan_GetDevice(i);
|
|
char* buff = new char[30];
|
|
SlCan_DeviceGetProperty(device, 0x0000000D, buff, 30);
|
|
QString str(buff);
|
|
ui->serialPortInfoListBox->addItem(str);
|
|
delete[] buff;
|
|
}
|
|
ui->serialPortInfoListBox->setCurrentText(currPort);
|
|
ui->serialPortInfoListBox->setDisabled(FALSE);
|
|
}
|
|
|
|
static QString DeviceGetPropety(HSLCAN hDevice, DWORD dwIndex)
|
|
{
|
|
char pBuf[256];
|
|
SlCan_DeviceGetProperty(hDevice, dwIndex, pBuf, 256);
|
|
return QString(pBuf);
|
|
}
|
|
void CanUsb::on_serialPortInfoListBox_currentIndexChanged(int index)
|
|
{
|
|
device = SlCan_GetDevice(ui->serialPortInfoListBox->currentIndex());
|
|
ui->descriptionLabel->setText(tr("Description: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_DEVICEDESC)));
|
|
ui->descriptionLabel->setToolTip(QString("Description: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_DEVICEDESC)));
|
|
|
|
ui->manufacturerLabel->setText(tr("Manufacturer: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_MFG)));
|
|
ui->manufacturerLabel->setToolTip((QString("Manufacturer: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_MFG))));
|
|
|
|
ui->serialNumberLabel->setText(tr("Serial number: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_SERIAL)));
|
|
ui->serialNumberLabel->setToolTip(QString("Serial number: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_SERIAL)));
|
|
|
|
ui->locationLabel->setText(tr("Location: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_PORTNAME)));
|
|
ui->locationLabel->setToolTip(QString("Location: %1").arg(DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_PORTNAME)));
|
|
|
|
QString VBuf = DeviceGetPropety(device, SLCAN_PROPERTY_INDEX_INSTANCEID);
|
|
QString VID;
|
|
QString PID;
|
|
bool FirstFlag = FALSE;
|
|
bool SecondFlag = FALSE;
|
|
for(int i = 0; i < VBuf.size(); i++)
|
|
{
|
|
if(VBuf[i]=='_')
|
|
{
|
|
FirstFlag=TRUE;
|
|
i++;
|
|
}
|
|
if(FirstFlag)
|
|
{
|
|
if(VBuf[i]=='&')
|
|
{
|
|
FirstFlag=FALSE;
|
|
SecondFlag=TRUE;
|
|
}
|
|
else if(SecondFlag!=TRUE)
|
|
{
|
|
VID+=VBuf[i];
|
|
}
|
|
else
|
|
{
|
|
if(VBuf[i]==0x5C)
|
|
{
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
PID+=VBuf[i];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ui->vidLabel->setText(tr("Vendor Identifier: %1").arg(VID.toLower()));
|
|
ui->vidLabel->setToolTip(QString("Vendor Identifier: %1").arg(VID.toLower()));
|
|
|
|
ui->pidLabel->setText(tr("Product Identifier: %1").arg(PID.toLower()));
|
|
ui->pidLabel->setToolTip(QString("Product Identifier: %1").arg(PID.toLower()));
|
|
}
|
|
|
|
int CanUsb::GetID()
|
|
{
|
|
return ui->dataBitsBox->currentText().toInt(nullptr, 16);
|
|
}
|
|
int CanUsb::GetBR()
|
|
{
|
|
return ui->baudRateBox->currentIndex();
|
|
}
|
|
HSLCAN CanUsb::G_Device()
|
|
{
|
|
return device;
|
|
}
|
|
int CanUsb::GetMode()
|
|
{
|
|
return ui->modeBox->currentIndex()+1;
|
|
}
|
|
void CanUsb::AfterConnection()
|
|
{
|
|
ui->parametersBox->setEnabled(FALSE);
|
|
ui->selectBox->setEnabled(FALSE);
|
|
}
|
|
|
|
void CanUsb::AfterDisconnection()
|
|
{
|
|
ui->parametersBox->setEnabled(TRUE);
|
|
ui->selectBox->setEnabled(TRUE);
|
|
}
|
|
|
|
int CanUsb::GetCount()
|
|
{
|
|
return ui->serialPortInfoListBox->count();
|
|
}
|