在cpp中的窗体访问上的串行端口 [英] serialport on form access in cpp

查看:62
本文介绍了在cpp中的窗体访问上的串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用c ++ visual studio 2008 Express,编写了一个程序来控制机器人.

我在主要形式"serialPort1"上有一个串行端口,并希望通过cpp文件"robot 300610.cpp"与之通讯.

有人可以帮我语法吗?

我可以在"Form1.h"中使用串行端口,但不能在其他地方使用.

我只需要在端口上写一个字符串即可.

我已经用谷歌搜索并尝试了所提供的方法,但都没有成功.由于我是C ++的新手,到目前为止,我已经在汇编器中完成了所有编程工作,因此,我不知道所有语法,甚至都不知道C ++中的所有内容. br/>
谢谢,
Dave Everett

Hi,

I am using c++ visual studio 2008 express, writing a program to control a robot.

I have a serialport on the main form ''serialPort1'' and wish to talk to it from the cpp file ''robot 300610.cpp''.

Could someone please help me with the syntax?

I can use the serialport inside ''Form1.h'' but not from elsewhere.

I only need to write a string to the port.

I have googled this and tried the methods offered without success and as I''m new to C++, having done all my programming in assembler up to this point, I do not know all the syntax or even what everything is called in C++.

Thanks,
Dave Everett

推荐答案

我可以在Form1.h内使用串行端口,但不能在其他地方使用串行端口"这句话是什么意思?我假设您正在使用托管C ++(又名C ++/CLI)来构建程序,但实际上您想使用纯C ++.看一下这些文章 [
What do you mean by the sentence "I can use the serialport inside ''Form1.h'' but not from elsewhere."? I assume you are using managed C++ (aka C++/CLI) to build your program but you actually want to use pure C++. Take a look at some of these articles[^] for some suggestions as to how you may do it.


感谢Richard.

我的意思是我不能在表格代码中使用串行端口:
this-> serialPort1-> Write(!SCVER?");
导致该字符串从串行端口发送到设备,但是该行在我的主cpp文件中不可用.
我需要控制主cpp文件中的端口.

程序是CLR,我将设置更改为Pure C ++,但是在编译某些OpenCV文件时在生成过程中会产生错误.

不幸的是,您的回复中的文章链接会转到空白的搜索窗口.

戴夫·埃弗里特(Dave Everett)
Thanks Richard.

I mean''t I can use the serial port inside the form code:
this->serialPort1->Write("!SCVER?");
results in that string being sent out the serial port to the device, but that line is not usable in my main cpp file.
It''s in the main cpp file that I need to control the port.

The program is CLR, I changed the setting to Pure C++ but that generates errors during build when some of the OpenCV files are compiled.

Unfortunately the article link in your reply goes to a blank search window.

Dave Everett


这篇关于在cpp中的窗体访问上的串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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