所以我正在编写一个串行传输程序,并且刚刚转换为使用C++,因为我使用C++已经有一段时间了(我最近一直在使用C,之前是java)
现在我需要使用LibSerial,(它似乎比C的termios更简单)
我的代码是:
//gen1.cpp
#include "string2num.h" // a custom header
#include <iostream>
#include <SerialStream.h>
using namespace LibSerial;
//using namespace std;
int main(int argc, char*argv[])
{
if (argc<2)
{
std::cout<<argv[0]<<"requires the device name eg \"dev/tty0\" as a parameter\nterminating.\n";
return 1;
}
SerialStream theSerialStream(argv[1]); //open the device
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我编译输出时:
g++ -Wall -o gen1 gen1.cpp string2num.o
/tmp/cchPBWgx.o: In function `main':
gen1.cpp:(.text+0x121): undefined reference to `LibSerial::SerialStream::SerialStream(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Ios_Openmode)'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x24): undefined reference to `LibSerial::SerialStreamBuf::showmanyc()'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x28): undefined reference …Run Code Online (Sandbox Code Playgroud) 将参数传递给cpu堆栈上的函数时,
你把参数放在然后JSR将返回地址放在堆栈上.因此,这意味着在您的函数中,您必须先取出堆栈的顶部项(返回地址),然后才能关闭其他项目)
返回值按惯例存储在寄存器中D0.
例如,以下是正确的方法:
...
|Let’s do some addition with a function,
MOVE.L #4, -(SP)
MOVE.L #5, -(SP)
JSR add
|the result of the addition (4+5) is in D0 (9)
...
add:
MOVE.L (SP)+, A1 |store the return address
|in a register
MOVE.L (SP)+, D0 |get 1st parameter, put in D0
MOVE.L (SP)+, D2 |get 2nd parameter, put in D2
ADD.L D2, D0 |add them,
|storing the result in D0
MOVE.L A1, -(SP) |put the address back on …Run Code Online (Sandbox Code Playgroud) 我有两个接口:
IState和IAction.State有一个方法:GetActions - 返回IActions的集合.一个Action有一个方法:Apply - 作用于一个State,返回一个新的State.
IState接受一个类型参数来控制它通过get动作返回的操作类型,IAction接受一个类型参数来控制它可以作用的状态.(通过排序,我实施).我希望能够保证国家只返回可以对同一类型的国家采取行动的行动.
type IAction<'S when 'S:>IState> =
abstract member Apply : 'S->'S
and IState<'A when 'A:>IAction<'S when 'S:> typeof(this)>> =
abstract member GetActions : seq<'A>
Run Code Online (Sandbox Code Playgroud)
但显然typeof(this)不是一件事.我怎样才能有一个类型约束,确保我的类型参数类型与我定义的类型相同?
在朱莉亚,我可以得到一个像这样的字段列表
INPUT:
type Foobar
foo::Int
bar::String
end
baz = Foobar(5,"GoodDay")
fieldnames(baz)
OUTPUT:
2-element Array{Symbol,1}:
:foo
:bar
Run Code Online (Sandbox Code Playgroud)
但是,考虑到我动态找到的名称,如何访问这些字段的值?
fieldvalue(v,fn::Symbol) = eval(Expr(:(.), v, QuoteNode(fn)))
Run Code Online (Sandbox Code Playgroud)
这有点可怕,所以我认为有更好的方法.
INPUT:
function print_structure(v)
for fn in fieldnames(v)
println(fn,"\t", fieldvalue(v,fn))
end
end
print_structure(baz)
OUTPUT:
foo 5
bar GoodDay
Run Code Online (Sandbox Code Playgroud) 我使用的是v0.6,但某些软件包不能与v0.6一起运行(例如Interact.jl).我该如何安装v0.5?我正在运行Ubuntu 16.04.
我永远不会记得如何做到这一点.
怎么可能去
(n1))到列矩阵(大小(n1,1))?(n1,n2))到数组{T,3}(大小(n1,n2,1))?(n1,n2,n3))到数组{T,4}(大小(n1,n2,n3, 1))?我想知道使用Array并使用它来定义一个带有额外单例尾随维度的新数组.即相反squeeze
我只是想hold on在Julia中寻找相当于Matlab的命令.
我有x15x1的yArray 和15x6的Array,所以这将同时制作6个图.我想要做的是一次绘制每y[:,1],y[:,2],...,y[:,6]一个(暂停说每个之间5秒),以便更好地说明数值方法的收敛,而不是一次性地将所有6次迭代打到那里.
我正在使用pyplot带有Plots.jl包的后端.
有tensorflow.pad()的示例:
Run Code Online (Sandbox Code Playgroud)# 't' = is [[1, 2, 3], [4, 5, 6]]. # 'paddings' is [[1, 1,], [2, 2]]. # rank of 't' is 2. ' tf.pad(t, paddings, "CONSTANT")' ==> [[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 0, 0], [0, 0, 4, 5, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0]]
我的问题是如何在每个输入维度中填充零?并且t的形状为[2,3],为什么pad()之后的输出为[4,x],“ 4”如何出现?感谢您的帮助!!!
我有以下二维数组:
[120 320;
150 270;
230 250]
Run Code Online (Sandbox Code Playgroud)
我想根据每行中的第二个元素对其中的行进行排序。我无论如何都找不到使用 Julia 的Base.sort(). 是否可以使用Base.sort()或有其他选择来实现这一目标?
julia ×6
.net ×1
68000 ×1
arrays ×1
assembly ×1
c++ ×1
f# ×1
g++ ×1
generics ×1
installation ×1
matplotlib ×1
motorola ×1
plot ×1
posix ×1
python ×1
reflection ×1
serial-port ×1
sorting ×1
stack ×1
tensorflow ×1