You can directly get custom table using objectmanager concept,
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$connection = $objectManager->get('Magento\Framework\App\ResourceConnection')->getConnection('\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION');
$result1 = $connection->fetchAll("SELECT * FROM my_table");
echo "<pre>";print_r($result1);
Or
This is proper way using block:
public function __construct(
Context $context,
\Namespace\Module\Model\ModuleFactory $modelFactory,
array $data = array()
) {
$this->_modelFactory = $modelFactory;
parent::__construct($context, $data);
}
You can get collection by factory methods:
public function getCollection(){
$this->_modelFactory->create()->getCollection()
->addFieldToFilter('serial_number',array('eq' =>'1'));
}