帮助将VB转换为C# [英] Help converting VB to C#

查看:90
本文介绍了帮助将VB转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用Elexol USBIO24.它具有24个I/O引脚,可以将其设置为高电平或低电平或用作输入.提供的代码示例在VB中,并且我认为我没有将其正确转换为C#.

他们的数据表具有以下内容:

打开端口
由于USBIO24单元使用二进制数据传输,因此我们必须以二进制模式使用端口.
如果端口号不正确或未连接USBIO24模块,则VB会生成错误.

MSComm1.CommPort = 3‘设置此数字,如设备管理器中所示
MSComm1.InputMode = comInputModeBinary‘设置二进制输入模式
MSComm1.PortOpen = True‘打开端口

将引脚设置为输入或输出
将端口设置为输入或输出时,必须确定要设置为输入的引脚的值.

要将引脚I/O1,I/O2和I/O3设置为输入,将其余引脚设置为输出,您只需将输入引脚1 + 2 + 4 = 7的位值相加,然后将其值放置在IOValx变量中在下面的示例代码中是7.

‘设置I/O1,I/O2&端口A的I/O3到输入,其余的作为输出.
IOValA = 7’前3个输入将所有其余部分作为输出
IOValB = 0‘所有输出
IOValC = 0‘所有输出
MSComm1.Output =!A" + Chr $(IOValA)''写入端口A方向寄存器
MSComm1.Output =!B" + Chr $(IOValB)''写入端口B方向寄存器
MSComm1.Output =!C" + Chr $(IOValC)''写入端口C方向寄存器

写给港口
要简单地写到输出引脚,请重复以上步骤,不要加上!!角色.
以下示例代码将端口B上的I/O8引脚设置为高电平,其余引脚设置为低电平.

IOValB = 128‘I/O8高,其余所有低

MSComm1.Output ="B" + Chr $(IOValB)

有人可以在这里将我指向VB的等效C#吗?

Hi,

I''m trying to work with an Elexol USBIO24. It has 24 I/O pins that can be set high or low, or used for input. The code samples provided are in VB, and I don''t think I''m converting it to C# properly.

Their datasheet has this:

Opening the Port
As the USBIO24 unit uses binary data transfer we must use the port in binary mode.
If the port number is incorrect or the USBIO24 module is not connected then VB will generate an error.

MSComm1.CommPort = 3 ‘ Set this number as shown in the Device Manager
MSComm1.InputMode = comInputModeBinary ‘ Set Binary Input Mode
MSComm1.PortOpen = True ‘ Open the Port

Setting the pins as Inputs or Outputs
Setting the Ports as Input or Output you must determine the value for the pins you want set as inputs.

To set pins I/O1, I/O2 and I/O3 as inputs and the remaining pins as outputs you simply add the bit values of the input pins 1 + 2 + 4 = 7 and thus the value to be placed in the IOValx variable in the following example code is 7.

‘ Set I/O1, I/O2 & I/O3 of port A to inputs and the rest as outputs.
IOValA = 7 ‘ First 3 inputs all the rest as outputs
IOValB = 0 ‘ All outputs
IOValC = 0 ‘ All outputs
MSComm1.Output = "!A" + Chr$(IOValA) '' Write to Port A Direction Register
MSComm1.Output = "!B" + Chr$(IOValB) '' Write to Port B Direction Register
MSComm1.Output = "!C" + Chr$(IOValC) '' Write to Port C Direction Register

Writing to the Ports
To write to the Output Pins simple repeat the Above without the ! character.
The following example code sets the I/O8 pin on port B to high and the remaining pins as low.

IOValB = 128 ‘ I/O8 high, all the rest low

MSComm1.Output = "B" + Chr$(IOValB)

Can anyone point me toward the equivalent C# for the VB here?

推荐答案

(IOValA)"写入端口A方向寄存器
MSComm1.Output =!B" + Chr
(IOValA) '' Write to Port A Direction Register
MSComm1.Output = "!B" + Chr


(IOValB)''写入端口B方向寄存器
MSComm1.Output =!C" + Chr
(IOValB) '' Write to Port B Direction Register
MSComm1.Output = "!C" + Chr


(IOValC)''写入端口C方向寄存器

写给港口
要简单地写到输出引脚,请重复以上步骤,不要加上!!角色.
以下示例代码将端口B上的I/O8引脚设置为高电平,其余引脚设置为低电平.

IOValB = 128‘I/O8高,其余所有低

MSComm1.Output ="B" + Chr
(IOValC) '' Write to Port C Direction Register

Writing to the Ports
To write to the Output Pins simple repeat the Above without the ! character.
The following example code sets the I/O8 pin on port B to high and the remaining pins as low.

IOValB = 128 ‘ I/O8 high, all the rest low

MSComm1.Output = "B" + Chr


这篇关于帮助将VB转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆