我正在开发一个运行Android的自定义平板电脑(由我的公司构建为销售工具)的应用程序.应用程序需要通过虚拟串行端口与连接的USB设备进行通信.驱动程序已安装并运行良好(它是Silicon Labs的CP2101 USB转UART桥控制器).我使用的是串行端口库,网址为:http://code.google.com/p/android-serialport-api/.
问题是无论何时安装设备我都无权在Android中打开它.Android串口库需要打开一个文件,通常是/ dev/ttyUSB0,但是应用程序没有这样做的权限.如果我打开adb shell并运行"chmod 666/dev/ttyUSB0",一切都很棒.当然,我需要一个更持久的解决方案.
我不认为init.rc会起作用,因为我希望能够在安装时修改设备文件,而不仅仅是在启动时.有没有办法强制Linux以更宽松的权限安装此设备(或任何设备)?
提前致谢.
我在Ubuntu上使用LibSerial在串口上读写数据.
目前,我能够通过串口写入和接收字符串,但我的代码不能很好地工作:特别是,我想控制读取功能,以便只有在有东西需要读取时才能读取并且当没有信息要读取时退出,以便发送另一个命令而不会使流程程序失败.
我想要做:
现在,我能够发送第一个命令并在while循环中使用read函数读取答案,但我无法做任何其他事情. 我无法发送第二个命令,因为while循环永远不会退出,所以程序继续读取.
你能帮我吗?
这是我正在使用的代码:(读写函数位于代码的末尾)
#include <SerialStream.h>
#include <iostream>
#include <unistd.h>
#include <cstdlib>
#include <string>
int
main( int argc,
char** argv )
{
//
// Open the serial port.
//
using namespace std;
using namespace LibSerial ;
SerialStream serial_port ;
char c;
serial_port.Open( "/dev/ttyACM0" ) ;
if ( ! serial_port.good() )
{
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] "
<< "Error: Could not open serial …Run Code Online (Sandbox Code Playgroud) 以下是通过PHP进行串行通信的库:http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html.问题是readPort方法没有完全实现.它可以在*nix环境中读取,但显然不在Windows环境中读取.方法:
/**
* Reads the port until no new datas are availible, then return the content.
*
* @pararm int $count number of characters to be read (will stop before
* if less characters are in the buffer)
* @return string
*/
function readPort ($count = 0)
{
if ($this->_dState !== SERIAL_DEVICE_OPENED)
{
trigger_error("Device must be opened to read it", E_USER_WARNING);
return false;
}
if ($this->_os === "linux")
{
$content = ""; $i = 0;
if …Run Code Online (Sandbox Code Playgroud) 好吧,我用google搜索从Arduino串口获取字符串,我甚至没有运气,甚至复制和粘贴示例.
我正在尝试从Serial中获取一个字符串.这是我的代码:
void setup() {
Serial.begin(9600);
Serial.write("Power On");
}
void loop()
{
while(!Serial.available());
while (Serial.available() > 0) {
Serial.write(Serial.read());
}
Serial.println();
}
Run Code Online (Sandbox Code Playgroud)
而且它逐个字符地打印出来.
我也试过了
char* read(int len) {
while (!Serial.available());
char str[len];
int i = 0;
while (i < len) {
str[i] = '\0';
int inByte = Serial.read();
Serial.println(inByte);
if (inByte == -1) {
return str;
} else {
str[i++] = inByte;
}
}
return str;
}
Run Code Online (Sandbox Code Playgroud)
并且它一次返回1个字符(serial.print(inByte)每隔一次返回-1).为什么Serial会分裂每个字符?
如果我输入'hello'并且我调用serial.read()它会给出一个字符然后说什么都没有,然后给另一个角色并且说什么都没有.
我正在通过串口读取微控制器的数据,波特率为921600.我正在读取大量的ASCII csv数据,因为它的速度非常快,所以其余的数据都被丢失了我可以读它.我知道我可以手动编辑serialwin32的pyserial源代码以增加缓冲区大小,但我想知道是否还有另一种方法呢?
我只能估计我将收到的数据量,但它大约是200kB的数据.
我正在使用Quartz.net,我试图让Quartz服务器在Windows服务中启动.我创建了一个Windows服务项目并包含了Quartz.net库.在我的服务类中,我有:
protected override void OnStart(string[] args)
{
try
{
Host host = HostFactory.New(x =>
{
x.Service<IQuartzServer>(s =>
{
s.SetServiceName("quartz.server");
s.ConstructUsing(builder =>
{
QuartzServer server = new QuartzServer();
server.Initialize();
return server;
});
s.WhenStarted(server => server.Start());
s.WhenPaused(server => server.Pause());
s.WhenContinued(server => server.Resume());
s.WhenStopped(server => server.Stop());
});
x.RunAsLocalService();
//x.RunAs(@"mydomain\mysusername", "mypassword");
x.SetDescription(Configuration.ServiceDescription);
x.SetDisplayName(Configuration.ServiceDisplayName);
x.SetServiceName(Configuration.ServiceName);
});
host.Run();
}
catch (Exception ex)
{
Log.Error(ex.Message);
Log.Error(ex.InnerException.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
我还创建了一个Windows服务安装程序,并使用以下命令在Visual Studio的命令提示符中成功安装了Windows服务:
installutil MyWindowsService.exe
当我在Windows服务列表中查看我的服务并尝试启动该服务时 - 我收到一个消息对话框:
The MyWindowsService service on Local Computer started and the
stopped. Some Services …Run Code Online (Sandbox Code Playgroud) 我有一个方法,有时可以在我的代码中调用.下面是一个非常基本的示例,因为代码处理iphone照片库中的图像和文件,并在完成该方法时标记它们已经处理过.
@property (nonatomic, assign) dispatch_queue_t serialQueue;
....
-(void)processImages
{
dispatch_async(self.serialQueue, ^{
//block to process images
NSLog(@"In processImages");
....
NSLog(@"Done with processImages");
});
}
Run Code Online (Sandbox Code Playgroud)
我认为每次调用此方法时我都会得到以下输出..."在processImages""使用processImages完成""在processImages""完成了processImages"等...
但我总是得到
"在processImages""在processImages""完成与processImages""完成与processImages"等...
我以为串口队列会等到第一个块完成,然后开始.对我来说,似乎它正在启动方法,然后它再次被调用并在第一个调用完成之前启动,创建通常不会被处理的图像的重复,因为如果它真的按顺序执行,则该方法将知道它们已经处理完毕.也许我对串行队列的理解并不具体.有什么输入?谢谢.
编辑:更多上下文,这是块中发生的事情...这可能导致问题???
@property (nonatomic, assign) dispatch_queue_t serialQueue;
....
-(void)processImages
{
dispatch_async(self.serialQueue, ^{
//library is a reference to ALAssetsLibrary object
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
....
//Process the photos here
}];
failureBlock:^(NSError *error) { NSLog(@"Error loading images from library");
}];
});
}
-(id)init
{
self …Run Code Online (Sandbox Code Playgroud) 在串行通信链路中,首选的成帧/同步方法是什么?
它是一个嵌入式系统,使用从UART到内存的DMA数据传输.我认为使用SOF的框架方法最具吸引力,但也许另一个方法足够好?
有没有人对这两种方法有利有弊?
我有一个小问题.
我从arduino附加的3轴加速度计+ 3轴磁力计+罗盘标题传递信息.这些缩放到midi范围(0-127).
ARDUINO:这是通过串行打印传递的,格式为76a45b120c23d12e23f34g
Serial.print(shiftAx);
Serial.print("a");
Serial.print(shiftAy);
Serial.print("b");
Serial.print(shiftAz);
Serial.print("c");
Serial.print(shiftMx);
Serial.print("d");
Serial.print(shiftMy);
Serial.print("e");
Serial.print(shiftMz);
Serial.print("f");
Serial.print(shiftHead);
Serial.print("g");
Run Code Online (Sandbox Code Playgroud)
我可以看到这使用我的串行监视器.(但我不确定是否以"g"打印为println.)
处理2:
我缓冲到我的void设置中的g()
port = new Serial(this, "/dev/tty.usbmodem411", 9600);
port.bufferUntil('g');
Run Code Online (Sandbox Code Playgroud)
我有这个功能
void serialEvent (Serial port)
{
data = port.readStringUntil('g');
AxVal = data.substring(0, data.indexOf('a'));
AyVal = data.substring(data.indexOf("a") + 1, data.indexOf("b"));
AzVal = data.substring(data.indexOf("b") + 1, data.indexOf("c"));
MxVal = data.substring(data.indexOf("c") + 1, data.indexOf("d"));
MyVal = data.substring(data.indexOf("d") + 1, data.indexOf("e"));
MzVal = data.substring(data.indexOf("e") + 1, data.indexOf("f"));
HeadVal = data.substring(data.indexOf("f") + 1, data.indexOf("g"));
}
Run Code Online (Sandbox Code Playgroud)
问题所以这不起作用.没有显示文字.(它只是一个简单的fill(),text())
我不明白为什么.问题是我的协议(如果我可以称之为),我是如何解压缩字符串的?或者其他一些问题. …
processing serial-port communication arduino serial-communication
我正在尝试通过 USB 串行端口从 Arduino 中提取一些数据并将其写入 txt 文件。因此,我正在使用批处理文件(Windows 7,普通 cmd),它发送例如“d”以从 Arduino 请求所需的数据。收到“d”后,Arduino 开始将数据发送到 PC。批处理文件读取数据并将其写入某个 txt 文件。批号为:
mode COM4 BAUD=9600 PARITY=n DATA=8
echo d >COM4
COPY COM4 data.txt
Run Code Online (Sandbox Code Playgroud)
到目前为止,这有效,但问题是:
如何停止复制过程?
当 Arduino 完成发送数据时,批处理文件会继续等待更多。我的首选解决方案是,Arduino 发送一些像“end”这样的字符串,批处理文件识别出这一点并停止读取。这有可能吗?
serial-port ×7
arduino ×3
linux ×2
android ×1
android-ndk ×1
batch-file ×1
c ×1
c# ×1
c++ ×1
ios ×1
libserial ×1
php ×1
processing ×1
pyserial ×1
python ×1
quartz.net ×1
queue ×1
stream ×1
text-files ×1
topshelf ×1
uart ×1
ubuntu ×1
usb ×1
windows ×1