First test of serial control
This commit is contained in:
parent
96a960a481
commit
760b8d06d0
1 changed files with 47 additions and 0 deletions
47
Dashboard/app/renderer/components/Test.js
Normal file
47
Dashboard/app/renderer/components/Test.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
import React, { useState } from 'react';
|
||||
import { useSelector, useDispatch } from 'react-redux/';
|
||||
|
||||
export default function Test() {
|
||||
const comConnection = useSelector((state) => state.comConnectionReducer);
|
||||
const [comData, setComData] = useState('');
|
||||
|
||||
comConnection.parser.on('data', (data) => {
|
||||
setComData(data);
|
||||
});
|
||||
|
||||
const triggerOn = () => {
|
||||
comConnection.port.write('on');
|
||||
};
|
||||
const triggerOff = () => {
|
||||
comConnection.port.write('off');
|
||||
};
|
||||
|
||||
const triggerOne = () => {
|
||||
comConnection.port.write('0');
|
||||
};
|
||||
const triggerTwo = () => {
|
||||
comConnection.port.write('1');
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ margin: 10 }}>
|
||||
<button onClick={triggerOn} style={{ marginRight: 10 }}>
|
||||
ON
|
||||
</button>
|
||||
<button onClick={triggerOff} style={{ marginRight: 10 }}>
|
||||
OFF
|
||||
</button>
|
||||
<button
|
||||
onClick={triggerOne}
|
||||
style={{ marginRight: 10, backgroundColor: comData[0] === '0' ? 'red' : 'green' }}>
|
||||
One
|
||||
</button>
|
||||
<button
|
||||
onClick={triggerTwo}
|
||||
style={{ marginRight: 10, backgroundColor: comData[1] === '0' ? 'red' : 'green' }}>
|
||||
Two
|
||||
</button>
|
||||
<p>{comData}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
Reference in a new issue