This commit is contained in:
parent
06b8560412
commit
5b2d4bce64
|
@ -73,12 +73,22 @@ ComProxy::ComProxy(COM com) :port(com)
|
|||
Name = port.Name;
|
||||
String name(Name);
|
||||
name.Show(true);
|
||||
|
||||
baudRate = 115200;
|
||||
|
||||
parity = 0x0000; // USART_Parity_No;
|
||||
dataBits = 0x0000; // USART_WordLength_8b;
|
||||
stopBits = 0x0000; // USART_StopBits_1;
|
||||
}
|
||||
|
||||
bool ComProxy::OnOpen()
|
||||
{
|
||||
return port.Open();
|
||||
// return true;
|
||||
if (port.Open())
|
||||
{
|
||||
port.SetBaudRate(baudRate);
|
||||
port.Set(parity, dataBits, stopBits);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ComProxy::OnClose()
|
||||
|
@ -90,13 +100,13 @@ bool ComProxy::OnClose()
|
|||
bool ComProxy::SetConfig(Dictionary<cstring, int>& config, String& str)
|
||||
{
|
||||
int value;
|
||||
if (config.TryGetValue("baudRate", value))
|
||||
if (config.TryGetValue("baudrate", value))
|
||||
{
|
||||
port.SetBaudRate(value);
|
||||
}
|
||||
|
||||
cstring ByteParam[] = { "parity","dataBits","stopBits" };
|
||||
byte* ParamP[] = {&parity, &dataBits, &stopBits};
|
||||
ushort* ParamP[] = {&parity, &dataBits, &stopBits};
|
||||
bool haveChang = false;
|
||||
for (int i = 0; i < ArrayLength(ByteParam); i++)
|
||||
{
|
||||
|
@ -114,7 +124,7 @@ bool ComProxy::SetConfig(Dictionary<cstring, int>& config, String& str)
|
|||
|
||||
bool ComProxy::GetConfig(Dictionary<cstring, int>& config)
|
||||
{
|
||||
config.Add("baudRate",baudRate);
|
||||
config.Add("baudrate",baudRate);
|
||||
|
||||
config.Add("parity", parity);
|
||||
config.Add("dataBits", dataBits);
|
||||
|
|
|
@ -43,9 +43,9 @@ public:
|
|||
|
||||
SerialPort port;
|
||||
|
||||
byte parity;
|
||||
byte dataBits;
|
||||
byte stopBits;
|
||||
ushort parity;
|
||||
ushort dataBits;
|
||||
ushort stopBits;
|
||||
int baudRate;
|
||||
|
||||
virtual bool OnOpen() override;
|
||||
|
|
|
@ -13,9 +13,9 @@ class SerialPort : public ITransport, public Power
|
|||
{
|
||||
private:
|
||||
byte _index;
|
||||
byte _parity;
|
||||
byte _dataBits;
|
||||
byte _stopBits;
|
||||
ushort _parity;
|
||||
ushort _dataBits;
|
||||
ushort _stopBits;
|
||||
int _baudRate;
|
||||
|
||||
void* _port;
|
||||
|
|
|
@ -168,24 +168,36 @@ bool ProxyFactory::GetConfig(const BinaryPair& args, Stream& result)
|
|||
// port->GetConfig(str); // 调用端口的函数处理内容
|
||||
// ms.Write(str);
|
||||
|
||||
Dictionary<cstring, int> cfg(String::Compare);
|
||||
Dictionary<cstring, int> cfg;
|
||||
port->GetConfig(cfg); // 调用端口的函数处理内容
|
||||
|
||||
// 数据先写进缓冲区ms2
|
||||
MemoryStream ms2;
|
||||
auto name = cfg.Keys();
|
||||
auto value = cfg.Keys();
|
||||
auto value = cfg.Values();
|
||||
|
||||
debug_printf("cfg count : %d value count : %d\t\t", name.Count(), value.Count());
|
||||
String str;
|
||||
|
||||
for (int i = 0; i < cfg.Count(); i++)
|
||||
{
|
||||
ms2.Write(String(name[i]));
|
||||
ms2.Write('=');
|
||||
ms2.Write(String(value[i]));
|
||||
if (i < cfg.Count() - 1) ms2.Write('&');
|
||||
str = str + name[i] + '=' + value[i];
|
||||
if (i < cfg.Count() - 1)str = str + ',';
|
||||
}
|
||||
// 然后组成名词对写进回复数据内去
|
||||
BinaryPair bp(ms);
|
||||
bp.Set("Config", Buffer(ms2.GetBuffer(), ms2.Position()));
|
||||
str.Show(true);
|
||||
//ms.Write(str);
|
||||
result.Write(str);
|
||||
|
||||
// for (int i = 0; i < cfg.Count(); i++)
|
||||
// {
|
||||
// ms2.Write(String(name[i]));
|
||||
// ms2.Write('=');
|
||||
// ms2.Write(String(value[i]));
|
||||
// if (i < cfg.Count() - 1) ms2.Write('&');
|
||||
// }
|
||||
// // 然后组成名词对写进回复数据内去
|
||||
// BinaryPair bp(ms);
|
||||
// bp.Set("Config", Buffer(ms2.GetBuffer(), ms2.Position()));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue